This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes Problem with size Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Problem with size" Watch "Problem with size" New topic
Author

Problem with size

Jennifer Sohl
Ranch Hand

Joined: Feb 28, 2001
Posts: 455
Hi. I have an app that has fields that are setVisible(false) when my application runs. If the user clicks a certain button, these fields are supposed to appear. My problem is when they appear, they are tiny. I think it is becuase when the app ran, these fields were not visible, so it didn't pack them.
I need to know how to be able to recognize these fields, even though they are not visible so my frame is large enough for them when they do appear.
I hope this makes sense!
Thanks for any help!
Wahid Sadik
Ranch Hand

Joined: Oct 30, 2000
Posts: 56
Hi,
Try to use setPreferredSize() method


Regards<br />Mohammod Wahid Sadik<br />SCJP 1.2, SCJD 1.4,<br />IBM Certified XML Developer<br />IBM Certified UML Designer
Jennifer Sohl
Ranch Hand

Joined: Feb 28, 2001
Posts: 455
Thanks for the reply! I have the set the size of my app. That works. Now the problem I have, is whenever the components are set to "setVisible(false)", Everything shifts so it's centered in the middle. I want all of my other components to stay where they are at!! Is this possibly a GridBagLayout manager issue? If so, what do I need to do to make my components stay where they are at when I set other components' visiblity to false?
Any help is greatly appreciated!!
Manfred Leonhardt
Ranch Hand

Joined: Jan 09, 2001
Posts: 1492
Hi Jennifer,
The problem is indeed GridBagLayout and there is really nothing you can do about this behavior.
You have two possible solutions:
1. Show the components but use setEnabled() instead of setVisible. This will at least show the user that those controls are not useable in the current "mode".
2. Use a dummy component, such as an empty frame, to swap with the actual component. Some problems with this approach would be: how to get the size for the actual componet ...
My personal choice would be number one because I hate GUIs that have components that appear and disappear.
Regards,
Manfred.
Jennifer Sohl
Ranch Hand

Joined: Feb 28, 2001
Posts: 455
Hi Manfred. I will use setEnabled(false). It works beautifully. However, I was wondering if there was a way to make a whole class not enabled. I have an address class that I am using in my main application and I would like to be able to do a setEnabled on the Address object and have it disable all the fields. Is there any way to do this, or do I have to do the old fashioned way, disabling every field in the Address class one by one?
Thanks a bunch!
Manfred Leonhardt
Ranch Hand

Joined: Jan 09, 2001
Posts: 1492
Hi Jennifer,
Unfortunately, I think you will need to call the method for each component. I can't seem to get anything else to work myself ...
Regards,
Manfred.
Nathan Pruett
Bartender

Joined: Oct 18, 2000
Posts: 4121

Well, if the address class extends JPanel (or another container...) you could implement a setEnabled( boolean ) method that does this...



It will enable or disable all components held within your address component...

-Nate


-Nate
Write once, run anywhere, because there's nowhere to hide! - /. A.C.
Jennifer Sohl
Ranch Hand

Joined: Feb 28, 2001
Posts: 455
Thanks for the help guys. You're great!!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problem with size
 
Similar Threads
Modal dialog box and request focus
Jasper Reports - Problem while viewing report in JSP
passing parameter from js to servlet
a4j rerendering problem.
static JTextField problem!