swing

Java Swing: positioning dialog on top of existing window

Can someone show simple Java Swing code/web resource that will position the popup dialog center-aligned on top of an existing JFrame window when the JFrame's button clicked? ...

Stop a jframe requesting focus

I have a small application that updates the contents of a JFrame very quickly (many times per second) and on each update (I remove a component and then add a new one, then set visibility true again) the JFrame flashes on the Taskbar (WinXp) to request focus. It's very annoying and I'm sure it can be disabled. I just cant find out where. ...

Why does Jython refuse to find my Java package?

I know it's something silly, but for some reason Jython refuses to find javax.swing. I'm using Java 1.6.0_11. This is my start-up script: @echo off "%JAVA_HOME%\bin\java" -Xmx1024M -classpath ".;c:\Projects\Jython2.5.1\jython.jar" org.python.util.jython My output looks like: Jython 2.5.1 (Release_2_5_1:6813, Sep 26 2009, 13:47:54)...

[Java] How to make an animation with Swing ?

Hi, I am making a JApplet and got stuck with a animation problem. Here is my code : this.sprite.setBounds(0,0,20,17); this.sprite.setIcon(this.rangerDown); for(int i = 0; i< 16;i++) { this.sprite.repaint(); this.sprite.setLocation(this.sprite.getX(), this.sprite.getY()+10); try{ Thread.currentThread().sleep(100); ...

JInternalFrame and Keybinding

How do I bind a function key say(F11 etc) to a JInternalFrame, so it can activate a particular action. I tried with the following this.getInputMap().put(KeyStroke.getKeyStroke("F11"), new AbstractAction() { public void actionPerformed(ActionEvent e) { System.out.println("Called"); } }); but it never gets calle...

How can I modify the shortcut/hotkey "description" in a swing JMenu item?

Our swing application uses the "spacebar" key as a shortcut key. In other words, if you press the spacebar anywhere within the application window, it will perform a certain behaviour. What's more, this same behaviour can also be performed by using a JMenuItem in the window's menu bar. The normal way to implement this is to simply ...

Convert Java resultset to String array

Hey everyone, I am writing a program that will query an MS access database, return the query as a result set, and then I want to ultimately convert that result set into a String array, so that I can pass it into the constructor of a Swing JComboBox - so the ComboBox will list the items returned by the query. I have been able to store t...

Swing: How to position JFrame N pixels away from the center of the screen at first setVisible()?

What's the code to position a JFrame N pixels (say 300 pixels in x-direction) away from the center of the screen before one calls setVisible(true)? ...

only mouse clicked event of jlabel update jlabel text property properly

i am using a java thread to update jlabel text value in my application but after it updated text on jlabel jlabel showing all past updated values and new value periodically in order via refreshing itself but when i use same update function within the mouseclick event of jlabel it is updating itself as i expected and showing last value o...

How can I resize the background of a JLabel or apply top and bottom borders only?

I've got sort of weird issue that I can't seem to figure out. I have something that looks like this: As you can see, "Blambo" is a JLabel with an opaque, red background. The label sits on top of a little grey bar that has a single pixel blackish border all the way around it. I'd like my red warning to match the bar it's sitting on ...

Add JScrollPane to a panel that shows an image

i have this little program for showing images on apanel.. but i'm not able to add a scroll to it.. and this is my code the class that extends jpanel to show the image: public class ShowPanel extends JPanel{ public ShowPanel(BufferedImage image, int height, int width) { this.image = image; this.height = height; this.width = width...

[Java] Containers class owner's child object having to add components into his parent's container problem

Hi, I am having problems dealing with containers and components in my JApplet. I don't put my code because I think there is no need for it. The main class owns the getContentPane(). Another class (let's call it class1) owns a JLayeredPane() and components that are added to it. Another class (let's call it class2) only have components...

How to create a JButton with a menu ?

I want to create a Toolbar for my application. If you click a button on that toolbar , it will pop-up a menu , just like the toolbar of eclipse. I don't know how to do it in Swing. Can someone help me please ? I've try google but found nothing. ...

Getting the value from a Swing component from outside the EDT

My current code looks like this: final String[] value = new String[1]; SwingUtilities.invokeAndWait(new Runnable() { public void run() { value[0] = textArea.getText(); } }); The use of a final array seems like a bit of a hack. Is there a more elegant solution? I've done a lot of searching, but I don't seem to be able...

display image after after on the panel with a time gap

import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.image.*; import java.io.*; import javax.swing.ImageIcon; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; public class Video implements ActionListener { static int width=480; static int he...

How to copy styled text in JTextPane

I'm trying to create a WYSIWYG editor using JTextPane. I'm using DefaultEditorKit.CopyAction to copy text in the editor. But this method does not preserve the style of the text. Can someone tell me how to copy the text in JTextPane and preserve the style, please ? ...

Basic Java Question, Classes updating GUI

I will try and illustrate my question with examples, I am attempting to create a Java program that will (eventually) incorporate a complex Swing GUI. I have Main.java public class Main extends JFrame implements ActionListener { JTextArea example; public Main() { //... Missing, basic swing code example = new J...

Add an SWT widget to a swing JPanel

I understand that this may be impossible, but I would sure like to know if somebody has accomplished this, or have a work-around. I have an SWT Button and am wanting to overwrite an existing JPanel's contents with just the Button being present. My current strategy is to have the SWT Button as an initial null field and then set it throug...

Java AWT/Swing: Get notified on change of position/size of my window

Hello I've got a window and I would like to get notified when the position or the size has changed. Which type of listener ist the best to take? WindowListener didn't work for me... Any way? Thanks and regards ...

Swing object: first setText() gets "stuck" when using Mac Java SE 6

Hi there, I am a Java newbie trying to maintain an application that works fine under J2SE 5.0 (32- and 64-bit) but has a very specific problem when run under Java SE 6 64-bit: [Tims-MPB:~] tlynch% java -version java version "1.6.0_15" Java(TM) SE Runtime Environment (build 1.6.0_15-b03-226) Java HotSpot(TM) 64-Bit Server VM (build 14.1...