Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How do I specify a component's exact size?  RSS feed

 
Dale DeMott
Ranch Hand
Posts: 515
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Obviously the Swing class often controls the size of components. I want to be able to control the size at times as well. Is this possible? This would give me more control of look at feel rather than letting Swing fully take control.
-Dale
------------------
What's this H2SO4 doing in my fridge?? ( thud )
 
eric moon
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Depending on the layout manager you are using, you will have to set:
setPreferredSize();
setMinimumSize();
and
setMaximumSize();
If you want to control the exact position for all your components, you can set the layout manager to null, and call setBounds() for each one. This is a lot of work....
HTH
 
Vishakha Ahuja
Ranch Hand
Posts: 191
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, I'm not sure in Swing but in AWT, we have to setLayout(null) to be able to control the size of the components.
 
Matt Robinson
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It all depends on which layout manager you use... some layout managers pay attention to preferred size only, others pay attention to a different combination of those three sizes. Maybe take a look at the beginning of chapter 4 here for a quick summary of how they work... http://www.spindoczine.com/sbe Layout managers are ultimately responsible for the size of each component.
------------------
Matthew Robinson co-author of "Swing" (1999, Manning Publications). Freely available at http://www.spindoczine.com/sbe
 
Dale DeMott
Ranch Hand
Posts: 515
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sounds good. So as I understand it, some layout managers control the size of the components. Is there a way to force it so the component doesn't control the size but the programmer does. I know that some have the control, but sometimes I want the control of it. Or is this a factor of choosing the right layout manager.
-Dale

------------------
What's this H2SO4 doing in my fridge?? ( thud )
 
Charles Talbott
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The simplest way is to choose an appropriate layout manager. However, it is possible to control it (the way you would with MFC for example) according to 'The Complete Java2 Certification Study Guide'. Good luck!
------------------
Charles Talbott
Sun Certified Java 2 Programmer
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!