Swing Section Index | Page 31
How do I display an image in the background of a Swing component?
You'll need to subclass the component, make sure it is not opaque, and override the paintComponent() method such that the image is drawn before the superclass' paintComponent() method is called.
...more
Is there a mailing list for Swing-related questions?
Eastfork Object Space manages two Swing mailing lists, separate ones for the basic and more advanced questions. Signup information is available at http://www.eos.dk/archive/swing/index.html.more
How can I change the size of an Applet/JApplet in a Web Page?
Short answer: you can't.
The browser defines a fixed-sized area in the web page for the Applet. If you need dynamic sizing, your only choice is to have your Applet display a Frame, Window, or Dia...more
What exactly is the "Event Dispatch" thread (aka "AWT" Thread)?
When you run a GUI applet or application, the code in your main() method creates a GUI and sets up event handling. When you call setVisible(true) for your Frame, Window, Dialog, or when the browse...more
Which Swing component methods are thread-safe and not required to run in the event dispatch thread?
The repaint(), revalidate(), and invalidate() methods do not need to execute in the event dispatch thread (also known as the AWT thread). Any other methods which affect the state of a component mu...more
How do I ensure a specific row is visible in my JTable?
To ensure a specific row (or cell) is visible, you need to get the rectangle surrounding a specific row/column (cell) than make sure that is visible:
Rectangle rect =
table.getCellRect(row, c...more
How do I delete a row from a JTable?
The answer depends on the model you're using...
If you've called setModel() for the JTable in question, you must examine the class of the actual model you're using to see how (and if) it allows r...more
How do I capture a screendump of a Swing-based GUI?
As long as you don't need the window manager adornments, you can use the RepaintManager to capture the image on any Swing component:
RepaintManager manager = RepaintManager.currentManager(compone...more
How do I load an HTML file synchronously into an HTMLDocument?
// Convert urlString into a BufferedReader
URL url = new URL(urlString);
URLConnection connection = url.openConnection();
InputStream is = connection.getInputStream();
InputStreamReader isr = new...more
How do I change the current look and feel of my Swing program?
You can either call the setLookAndFeel() method of the UIManager class or set the swing.defaultlaf property of your Java program before it starts.
If you wish to change the look and feel of a runn...more
How do I find out which mouse button is pressed for a MouseEvent?
For AWT programs, you need to compare the modifiers of the event to the button masks of the INPUT_EVENT.
Left
InputEvent.BUTTON1_MASK
Middle
InputE...more
How do I run Swing Applets in a Browser?
While technically possible to use the Swing components in any Java 1.1-based browser, realistically is another story. The JAR file of Swing classes is approximately 2 MB, which would be required t...more