• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

determining minimum dimensions of an Applet

 
Clayton Cramer
Ranch Hand
Posts: 41
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2476
8
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 41
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2476
8
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Post your SSCCE that demonstrates the problem.
 
Paul Clapham
Sheriff
Pie
Posts: 20208
26
MySQL Database
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5116
11
Java Netbeans IDE Opera
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Darryl Burke
Bartender
Posts: 5116
11
Java Netbeans IDE Opera
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 41
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 41
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 41
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2476
8
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 41
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2476
8
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic