AWT Section Index | Page 4
In case of images how does thread spawning work? Can I stop the AWT from creating a thread for the image while loading?
You seem to think that a new thread is created for each image you download. That's simply not the case. Most AWT implementations use a small pool of threads (usually 4) for downloading images. The...more
What is the default layout manager of an applet?
For a java.applet.Applet, the default layout manager is FlowLayout.
For the content pane of a javax.swing.JApplet, the default layout manager is a BorderLayout.
How can I restrict the size of a component in a BoxLayout?
BoxLayout respects the preferred, maximum and minimum sizes of its managed components.
You can manage the sizes in two ways:
Subclass your components and override their sizing methods:
getPref...more
Why aren't printing-related topics covered in the I/O FAQ? It seems like an I/O issue.
Printing is done with AWT classes and thus covered in the AWT FAQ. See How do I print a multi-page text document? for one example, though the API has changed with every release of Java.more
How do I draw underlined text in an AWT Label component?
You can create your own Label class extending original java.awt.Label class and override the paint method.
For example
import java.awt.*;
public class MyLabel extends Label {
public MyLab...more
How can I get a reference to the container to which a component has been added?
Call
component.getParent();
Can I hide the grey TextField border in an applet while still displaying the text?
You can't. You have no control over the display of the AWT components. They use the native widget set (are drawn outside Java).
How can I determine all of the components contained in a JFrame?
To get a list of all components in a JFrame, you could need to write a recursive method like the following:
public void getAllComponents(Component c, Collection collection) {
collection.add(c)...more
How do I write a status bar in AWT/Swing?
Here's something I just knocked up. If you use this example remember to add your main component to the CENTER of the frame's content pane.
[FAQ Manager Note] Note that you can have anything you ...more
Why does getPreferredSize() return (0,0) for my frame? (Or why does pack() crunch my frame to nothing?)
This happens if you don't have a layout manager set for the components inside the frame.
If you use appropriate layout managers, you should see decent results from pack().
For details on using l...more
How can I construct a Flowchart in Java Swing?
There are some toolkits that might help with the graph construction. Tom Sawyer's in particular, has some very nice automated graph layout support.
http://www.jhotdraw.org/
http://www.tomsawyer....more
How do we stop the AWT Thread? Our Swing application will not terminate.
You need to explicitly call System.exit(exit_value) to exit a Swing application. This is because the event dispatcher thread is not a Daemon thread, and won't allow the JVM to shut down when othe...more
Can someone please explain the use of getMinimumSize()?
See my article on layout management, Effective Layout Management.
http://developer.java.sun.com/developer/onlineTraining/GUI/AWTLayoutMgr/index.html
The basic idea is that the components state t...more
How can I determine the active JFrame?
Call Frame.getFrames() which will return all frames created by the application.
Frame[] f = Frame.getFrames();
Frame active = null;
for (int i = 0; i < f.lenght; i++) {
if (f[i].isActive()...more
Where can I learn (more) about Java's support for developing multi-threaded programs?
Check out the jGuru Threads
FAQ.