Help coderanch get a
new server
by contributing to the fundraiser
  • 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

Layout Managers and preferred size

 
Ranch Hand
Posts: 455
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi. I am having a problem laying out a gui. I want to place five buttons and five labels on a panel. I want the button to have a corresponding label. I can do this with Grid Layout. However, I want the buttons to be small. Grid Layout will not let me set the size of the buttons. What would be the best way of going about this?
I'm pretty new with layout managers so bear with me (I was using visual age before to do GUI!).
Thanks a million!
 
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,
One thing you might want to consider is explicitly placing components where you want them of the height and width you want them.

setLayout(null);

and then look at the Component.setBounds() method to set the location, height, and width.

Good Luck,
-Dirk Schreckmann
[ February 19, 2002: Message edited by: Dirk Schreckmann ]
 
Ranch Hand
Posts: 1492
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Jennifer,
The beauty of java is that you can do it many different ways. See the code below to see how to do it using two different layout approaches.

Enjoy,
Manfred.
 
Ranch Hand
Posts: 2823
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why do people always want to cop out and suggest and use null layout?
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,
Did you feel like making an intelligent argument to not know about setLayout(null)?
[ February 19, 2002: Message edited by: Dirk Schreckmann ]
 
Bartender
Posts: 2205
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Null layouts totally loose out on the dynamic resize features of layout managers.
I have never worked on UI code that at some point did not need some kind of modification. If you hard code every position and size on your screen, you have a TON of extra work to add a button here or a combo box there.
Don't use null layouts. Learn to harness the power of LayoutManager!!!
 
Paul Stevens
Ranch Hand
Posts: 2823
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have yet to see a UI that has to use the null layout. Once you use it, you also have to set the resizing of your window to off. If you don't, you have to place a great deal of code into your app just to make it appear proportional to where you started. The Layout Managers provide all of this functionality for you. The argument has been made many times in this forum against the use of null layout. It is a broken record. The difference between the null layout and the others is that it takes time to learn the other layouts and how they can be combined to do whatever you want. We can also talk about adding new components to an existing layout. Using the null all components need to be repositioned manually. With the other layout managers you may just need to add the component. If you need more argements against the use of null layout, just search this forum. There are plenty against.
Now why don't you provide an argument for their use.
 
Ranch Hand
Posts: 3141
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Jennifer,
You can also get what you want by creating a custom component. Try the following, it produces 5 10x10 labeled buttons.

Hope that helps.
[ February 20, 2002: Message edited by: Jane Griscti ]
 
reply
    Bookmark Topic Watch Topic
  • New Topic