Client-Side Development Section Index | Page 87
How do I make text typed in a TextArea appear in uppercase only?
The key to solving this problem is to subclass TextArea and intercept
any KeyEvent sent. You need to check to see if the typed
key is a lower case character (be careful to keep this independent ...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 get all the font names supported by java using jdk1.1.8?
There are two "types" of font names you can deal with in Java
Logical Font Names
System Font Names
Logical font names are the names Java uses for platform independence. These are na...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
I'm using the Java Plug-in and need to modify the policy file. Why isn't the Plug-in picking up my changes?
The Plug-in reads the policy file and key store only once at startup. If you need to modify either, you need to shutdown and restart the browser.
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 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
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 the screen size of the user's machine?
The AWT Toolkit object provides information about the user's runtime platform. To find out what size in pixels the users's screen is, use the getScreenSize() method.
import java.awt.*;
public cla...more
My graphics card only supports 16 colors. Can I still use Java?
All graphical applications require at least 256 colors. Console-based programs like servlets or the compiler are not limited by this capability.
How do I get an applet to load a new page into the browser?
In short, get the applet's context and tell it to show a
different document: getAppletContext().showDocument(new URL("http://foo.com/whatever/blah.doc")).
You can also provide a target f...more
How can I download a file (for instance, a Microsoft Word document) from a server using a servlet and an applet?
Try telling the applet to call getAppletContext().showDocument("http://foo.com/whatever/blah.doc"). That makes the browser responsible for fetching and saving the document (including pu...more