Java Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesJava Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Get inside! Sample the range of functionality easily built with JMSL Library for Time Series Data Analysis, Heat Maps, Portfolio Optimization, Monte Carlo Simulation, Stock Price Charting and more. Download Now!
  #1  
Old May 5th, 2008, 10:22 PM
xlordt's Avatar
xlordt xlordt is offline
Only the strong survives!!.
Dev Shed God 1st Plane (5500 - 5999 posts)
 
Join Date: Feb 2003
Location: A World of wonder.
Posts: 5,543 xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)  Folding Points: 108894 Folding Title: Super Ultimate Folder - Level 1Folding Points: 108894 Folding Title: Super Ultimate Folder - Level 1Folding Points: 108894 Folding Title: Super Ultimate Folder - Level 1Folding Points: 108894 Folding Title: Super Ultimate Folder - Level 1Folding Points: 108894 Folding Title: Super Ultimate Folder - Level 1Folding Points: 108894 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 4 Weeks 1 Day 22 h 45 m 4 sec
Reputation Power: 378
Send a message via ICQ to xlordt Send a message via AIM to xlordt Send a message via MSN to xlordt Send a message via Yahoo to xlordt Send a message via Google Talk to xlordt Send a message via Skype to xlordt
Facebook
Swing - Best way of using Layouts

What is the best way to use layouts? for example.. I want to layout two buttons.. one next to each other.. (top/left area) with a space between them. Been reading about boxlaouts/cardlayouts etc.. cant seem to find the one that fits.

Reply With Quote
  #2  
Old May 6th, 2008, 04:34 AM
Hugh of Borg's Avatar
Hugh of Borg Hugh of Borg is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Jun 2004
Location: Switzerland
Posts: 568 Hugh of Borg User rank is Second Lieutenant (5000 - 10000 Reputation Level)Hugh of Borg User rank is Second Lieutenant (5000 - 10000 Reputation Level)Hugh of Borg User rank is Second Lieutenant (5000 - 10000 Reputation Level)Hugh of Borg User rank is Second Lieutenant (5000 - 10000 Reputation Level)Hugh of Borg User rank is Second Lieutenant (5000 - 10000 Reputation Level)Hugh of Borg User rank is Second Lieutenant (5000 - 10000 Reputation Level)Hugh of Borg User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 6 Days 19 h 4 m 40 sec
Reputation Power: 82
In my experience the best way is to look at the Visual Guide to Layout Managers and read the descriptions.

For your specific problem I'd suggest a FlowLayout. Or maybe a GridBagLayout or a SpringLayout if you have a few other components and don't want to nest panels...

Definitely not CardLayout, that does something completely different. BoxLayout are very specific in their use. You use it if you need all the cells to have the same dimensions. It could work in your case but is probably isn't what you are looking for...
__________________
- Hugh of Borg

The first thing young borg are taught: Keep away from Microsoft software!

Reply With Quote
  #3  
Old May 6th, 2008, 07:10 AM
crownjewel82's Avatar
crownjewel82 crownjewel82 is offline
rebel with a cause
Dev Shed God (5000 - 5499 posts)
 
Join Date: May 2004
Location: The Batsh!t Crazy State.
Posts: 5,349 crownjewel82 User rank is General 14th Grade (Above 100000 Reputation Level)crownjewel82 User rank is General 14th Grade (Above 100000 Reputation Level)crownjewel82 User rank is General 14th Grade (Above 100000 Reputation Level)crownjewel82 User rank is General 14th Grade (Above 100000 Reputation Level)crownjewel82 User rank is General 14th Grade (Above 100000 Reputation Level)crownjewel82 User rank is General 14th Grade (Above 100000 Reputation Level)crownjewel82 User rank is General 14th Grade (Above 100000 Reputation Level)crownjewel82 User rank is General 14th Grade (Above 100000 Reputation Level)crownjewel82 User rank is General 14th Grade (Above 100000 Reputation Level)crownjewel82 User rank is General 14th Grade (Above 100000 Reputation Level)crownjewel82 User rank is General 14th Grade (Above 100000 Reputation Level)crownjewel82 User rank is General 14th Grade (Above 100000 Reputation Level)crownjewel82 User rank is General 14th Grade (Above 100000 Reputation Level)crownjewel82 User rank is General 14th Grade (Above 100000 Reputation Level)crownjewel82 User rank is General 14th Grade (Above 100000 Reputation Level)crownjewel82 User rank is General 14th Grade (Above 100000 Reputation Level)  Folding Points: 32123 Folding Title: Starter FolderFolding Points: 32123 Folding Title: Starter Folder
Time spent in forums: 2 Months 3 Weeks 4 Days 16 h 11 m 14 sec
Reputation Power: 1935
The best way to use layouts is to use more than one. Split up the job between different panels and give each it's own layout.

But yea I'd probably opt for just a flow layout.
Comments on this post
mrider agrees: Absolutely. I always use several different panels.
__________________
The day I get my hands on the cookbook it's all over. -nicky

Reply With Quote
  #4  
Old May 6th, 2008, 09:14 AM
mrider's Avatar
mrider mrider is offline
Even I don't know what I do
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Mar 2005
Location: First star to the right, then straight on till morning.
Posts: 1,261 mrider User rank is Colonel (50000 - 60000 Reputation Level)mrider User rank is Colonel (50000 - 60000 Reputation Level)mrider User rank is Colonel (50000 - 60000 Reputation Level)mrider User rank is Colonel (50000 - 60000 Reputation Level)mrider User rank is Colonel (50000 - 60000 Reputation Level)mrider User rank is Colonel (50000 - 60000 Reputation Level)mrider User rank is Colonel (50000 - 60000 Reputation Level)mrider User rank is Colonel (50000 - 60000 Reputation Level)mrider User rank is Colonel (50000 - 60000 Reputation Level)mrider User rank is Colonel (50000 - 60000 Reputation Level)mrider User rank is Colonel (50000 - 60000 Reputation Level)mrider User rank is Colonel (50000 - 60000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 4 Days 12 h 38 m 57 sec
Reputation Power: 561
The trick is that some layout managers respect the size of your widget, but do not guarantee a correct overall layout. Others guarantee a correct overall layout, but your widgets will expand to fill the entire panel. The only time I use one layout is on the simplest page.
__________________
A -> B: Ride.
The road to enlightenment is more fun on two wheels.

The recent fuel price increase has had an interesting side effect. Many of the people that used to always say to me "You shouldn't ride a motorcycle, they're dangerous" are now saying "So, what kind of mileage do you get?"...

Last edited by mrider : May 6th, 2008 at 10:01 AM. Reason: English mrider, English...

Reply With Quote
  #5  
Old May 6th, 2008, 09:24 AM
crownjewel82's Avatar
crownjewel82 crownjewel82 is offline
rebel with a cause
Dev Shed God (5000 - 5499 posts)
 
Join Date: May 2004
Location: The Batsh!t Crazy State.
Posts: 5,349 crownjewel82 User rank is General 14th Grade (Above 100000 Reputation Level)crownjewel82 User rank is General 14th Grade (Above 100000 Reputation Level)crownjewel82 User rank is General 14th Grade (Above 100000 Reputation Level)crownjewel82 User rank is General 14th Grade (Above 100000 Reputation Level)crownjewel82 User rank is General 14th Grade (Above 100000 Reputation Level)crownjewel82 User rank is General 14th Grade (Above 100000 Reputation Level)crownjewel82 User rank is General 14th Grade (Above 100000 Reputation Level)crownjewel82 User rank is General 14th Grade (Above 100000 Reputation Level)crownjewel82 User rank is General 14th Grade (Above 100000 Reputation Level)crownjewel82 User rank is General 14th Grade (Above 100000 Reputation Level)crownjewel82 User rank is General 14th Grade (Above 100000 Reputation Level)crownjewel82 User rank is General 14th Grade (Above 100000 Reputation Level)crownjewel82 User rank is General 14th Grade (Above 100000 Reputation Level)crownjewel82 User rank is General 14th Grade (Above 100000 Reputation Level)crownjewel82 User rank is General 14th Grade (Above 100000 Reputation Level)crownjewel82 User rank is General 14th Grade (Above 100000 Reputation Level)  Folding Points: 32123 Folding Title: Starter FolderFolding Points: 32123 Folding Title: Starter Folder
Time spent in forums: 2 Months 3 Weeks 4 Days 16 h 11 m 14 sec
Reputation Power: 1935
Quote:
Originally Posted by mrider
The trick is that some layout managers respect the size of your widget, but does not guarantee a correct overall layout. Others guarantee a correct overall layout, but your widgets will expand to fill the entire panel.

And others will respect the size of your widget and guarantee a correct overall layout but are so god awful complicated to use that you might as well not bother. I'm looking at you GridBag and Spring Layout.

Reply With Quote
  #6  
Old May 6th, 2008, 09:56 AM
xlordt's Avatar
xlordt xlordt is offline
Only the strong survives!!.
Dev Shed God 1st Plane (5500 - 5999 posts)
 
Join Date: Feb 2003
Location: A World of wonder.
Posts: 5,543 xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)  Folding Points: 108894 Folding Title: Super Ultimate Folder - Level 1Folding Points: 108894 Folding Title: Super Ultimate Folder - Level 1Folding Points: 108894 Folding Title: Super Ultimate Folder - Level 1Folding Points: 108894 Folding Title: Super Ultimate Folder - Level 1Folding Points: 108894 Folding Title: Super Ultimate Folder - Level 1Folding Points: 108894 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 4 Weeks 1 Day 22 h 45 m 4 sec
Reputation Power: 378
Send a message via ICQ to xlordt Send a message via AIM to xlordt Send a message via MSN to xlordt Send a message via Yahoo to xlordt Send a message via Google Talk to xlordt Send a message via Skype to xlordt
Facebook
hmm ok, what If I was adding two buttons on top and a textbox at the bottom center, would I create different layouts for each container? like example.. (see comment in code)

java Code:
Original - java Code
  1. public void addPanel ()
  2.      {
  3.          JPanel p = new JPanel ();
  4.          
  5.          p.setLayout (new FlowLayout (5, 10, 49)); //Do I recreate and add this on ever new object?
  6.          p.setPreferredSize (new Dimension (400,200));
  7.          
  8.          button = new JButton ("Click Me Biatch");
  9.          
  10.          p.add (button);
  11.          
  12.          this.getContentPane ().add (p);
  13.      }

Reply With Quote
  #7  
Old May 6th, 2008, 12:09 PM
crownjewel82's Avatar
crownjewel82 crownjewel82 is offline
rebel with a cause
Dev Shed God (5000 - 5499 posts)
 
Join Date: May 2004
Location: The Batsh!t Crazy State.
Posts: 5,349 crownjewel82 User rank is General 14th Grade (Above 100000 Reputation Level)crownjewel82 User rank is General 14th Grade (Above 100000 Reputation Level)crownjewel82 User rank is General 14th Grade (Above 100000 Reputation Level)crownjewel82 User rank is General 14th Grade (Above 100000 Reputation Level)crownjewel82 User rank is General 14th Grade (Above 100000 Reputation Level)crownjewel82 User rank is General 14th Grade (Above 100000 Reputation Level)crownjewel82 User rank is General 14th Grade (Above 100000 Reputation Level)crownjewel82 User rank is General 14th Grade (Above 100000 Reputation Level)crownjewel82 User rank is General 14th Grade (Above 100000 Reputation Level)crownjewel82 User rank is General 14th Grade (Above 100000 Reputation Level)crownjewel82 User rank is General 14th Grade (Above 100000 Reputation Level)crownjewel82 User rank is General 14th Grade (Above 100000 Reputation Level)crownjewel82 User rank is General 14th Grade (Above 100000 Reputation Level)crownjewel82 User rank is General 14th Grade (Above 100000 Reputation Level)crownjewel82 User rank is General 14th Grade (Above 100000 Reputation Level)crownjewel82 User rank is General 14th Grade (Above 100000 Reputation Level)  Folding Points: 32123 Folding Title: Starter FolderFolding Points: 32123 Folding Title: Starter Folder
Time spent in forums: 2 Months 3 Weeks 4 Days 16 h 11 m 14 sec
Reputation Power: 1935
Pretty much. I like to use border layout for the parent frame.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesJava Help > Swing - Best way of using Layouts


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway