Meaningless Drivel is fun!*
The moose likes Swing / AWT / SWT and the fly likes determining minimum dimensions of an Applet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "determining minimum dimensions of an Applet" Watch "determining minimum dimensions of an Applet" New topic
Author

determining minimum dimensions of an Applet

Clayton Cramer
Ranch Hand

Joined: Aug 26, 2010
Posts: 41
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.
Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Posts: 2200
    
    7
Use a JApplet, not Applet.

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.
Clayton Cramer
Ranch Hand

Joined: Aug 26, 2010
Posts: 41
Rob Camick wrote:Use a JApplet, not Applet.

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?
Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Posts: 2200
    
    7
Post your SSCCE that demonstrates the problem.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18657
    
    8

No, you need a layout in which the components are all materialized. In other words, displayed on the screen. I believe I already suggested that. Why don't you do it?
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4642
    
    5

Clayton Cramer wrote: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.


Are you sure you're talking about an Applet/JApplet? What Java icon, the icon, maximize, and close buttons?


luck, db
There are no new questions, but there may be new answers.
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4642
    
    5

Paul Clapham wrote:No, you need a layout in which the components are all materialized. In other words, displayed on the screen.


Unless I've misunderstood you, this isn't needed. Example:
Clayton Cramer
Ranch Hand

Joined: Aug 26, 2010
Posts: 41
Rob Camick wrote:Post your SSCCE that demonstrates the problem.




When I execute it, I get

d=java.awt.Dimension[width=1,height=1]

on the console, even though the various components are clearly much larger.

Clayton Cramer
Ranch Hand

Joined: Aug 26, 2010
Posts: 41
Darryl Burke wrote:
Clayton Cramer wrote: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.


Are you sure you're talking about an Applet/JApplet? What Java icon, the icon, maximize, and close buttons?


Yes, to make it stand out (since it is a modal dialog for the application), I put it inside a JFrame, using this class:




Clayton Cramer
Ranch Hand

Joined: Aug 26, 2010
Posts: 41
Paul Clapham wrote:No, you need a layout in which the components are all materialized. In other words, displayed on the screen. I believe I already suggested that. Why don't you do it?


I did. And getPreferredSize() still returns 1, 1.
Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Posts: 2200
    
    7
I have no idea what you are doing. That is not an applet. I see a few methods:

a) inputTextBox(...);
b) editableTextBox(...);

Those methods are never invoked from within the applet.

When you execute the applet nothing happens.

If you want to display a frame or dialog from an applet then create a frame or dialog and display it there is no need to "add an Applet" to the frame or dialog.
Clayton Cramer
Ranch Hand

Joined: Aug 26, 2010
Posts: 41
Rob Camick wrote:I have no idea what you are doing. That is not an applet. I see a few methods:

a) inputTextBox(...);
b) editableTextBox(...);

Those methods are never invoked from within the applet.

When you execute the applet nothing happens.

If you want to display a frame or dialog from an applet then create a frame or dialog and display it there is no need to "add an Applet" to the frame or dialog.


How unfortunate. It works great! From a JSP:




and then I call a Javascript function:



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.
Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Posts: 2200
    
    7
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.
 
Don't get me started about those stupid light bulbs.
 
subject: determining minimum dimensions of an Applet