Win a copy of Five Lines of Code this week in the OO, Patterns, UML and Refactoring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

determining minimum dimensions of an Applet

 
Ranch Hand
Posts: 41
  • 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.
 
Rancher
Posts: 3191
29
  • 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
  • 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
Rancher
Posts: 3191
29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Post your SSCCE that demonstrates the problem.
 
Marshal
Posts: 25676
69
Eclipse IDE Firefox Browser MySQL Database
  • 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?
 
Bartender
Posts: 5167
11
Netbeans IDE Opera Java
  • 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: 5167
11
Netbeans IDE Opera Java
  • 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
  • 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
  • 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
  • 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
Rancher
Posts: 3191
29
  • 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
  • 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
Rancher
Posts: 3191
29
  • 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.
 
    Bookmark Topic Watch Topic
  • New Topic