I have an applet that pops up a window with several components: a JLabel, a JTextArea, and two buttons. Different callers will specify different sizes for the JTextArea, so I would like to setSize so that the Applet window shrinks to only the area that is used. This is the code that creates the components:
Here is the code that does the popup, and tries to resize the object:
Unfortunately, no method associated with the Applet seems to return the size of just the stuff that I have added. If this were a JFrame, I could use pack(), but Applet does not seem to spport this.
If you build your JApplet properly by using layout managers then it should have a preferred size since it uses a content pane the same as JFrame, JDialog and JWindow.
Thanks, not sure why I was using Applet instead of JApplet. I am using the BoxLayout, but the getPreferredSize method returns something very tiny--just enough room for the Java icon, the icon, maximize, and close buttons. I can enlarge it, but perhaps getPreferredSize isn't what I need? Or does BoxLayout not set these to the minimum sizes of all the components added to it?
This executes the inputTextBox method in the applet, bringing up a display. I admit that this is a somewhat unusual form of an applet, but it is one, and it works.
Joined: Jun 13, 2009
I admit that this is a somewhat unusual form of an applet...
And based on all previous comments in your original question how are we supposed to know what you are doing?
Three people wasted time attempting to answer the question assuming your where talking about a "normal applet". Even when you where asked to post a SSCCE you still didn't post code so that we could actually invoke the applet.
You still haven't posted code we can actually use to test the applet. I don't have any more time to spend. Good luck with the answer.