Choice of layout.

Reply

Join Date: Nov 2004
Posts: 89
Reputation: MrScruff is an unknown quantity at this point 
Solved Threads: 0
MrScruff's Avatar
MrScruff MrScruff is offline Offline
Junior Poster in Training

Choice of layout.

 
0
  #1
Dec 5th, 2004
Hey people, Im just wondering what type of layout you would recommend to set up a grid of labels and sliders:

This is the format that i would like them to be in.
JLabel - Jslider - JLabel
JLabel - Jslider - JLabel
Slider Name - Slider - Slider Value

With a gridLayout the sizes of space allocated to the component is the same - meaning there is an unnessaserly large amount of space for the JLabels.
A gridbagLayout also worked - however setting one up resulted in the sliders being horizontal along my screen and i need them to be vertical piled on one another. Otherwise it worked fine for what i need.

Thanks for any suggestions
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 6,143
Reputation: jwenting is just really nice jwenting is just really nice jwenting is just really nice jwenting is just really nice 
Solved Threads: 213
Team Colleague
jwenting's Avatar
jwenting jwenting is offline Offline
duckman

Re: Choice of layout.

 
0
  #2
Dec 6th, 2004
I guess you want the sliders lined up nicely?
Try a BorderLayout with the labels in the WEST and EAST and the sliders in the CENTER.
You'll get a BorderLayout with in each of WEST, EAST and CENTER a JPanel with a GridLayout.
Each GridLayout has 3 rows and 1 column.
NORTH and SOUTH are empty, you could use those for for example a text describing the entire block or just leave them be.

Something like
  1. contentPane = (JPanel) getContentPane();
  2. contentPane.setLayout(borderLayout1);
  3. contentPane.add(jPanel1, java.awt.BorderLayout.CENTER);
  4. jPanel1.add(jSlider1);
  5. jPanel1.add(jSlider3);
  6. jPanel1.add(jSlider2);
  7. contentPane.add(jPanel2, java.awt.BorderLayout.WEST);
  8. jPanel2.add(jLabel4);
  9. jPanel2.add(jLabel6);
  10. jPanel2.add(jLabel5);
  11. contentPane.add(jPanel3, java.awt.BorderLayout.EAST);
  12. jPanel3.add(jLabel1);
  13. jPanel3.add(jLabel3);
  14. jPanel3.add(jLabel2);

Swing UI design is often best done on a piece of paper using pencil and eraser.
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 89
Reputation: MrScruff is an unknown quantity at this point 
Solved Threads: 0
MrScruff's Avatar
MrScruff MrScruff is offline Offline
Junior Poster in Training

Re: Choice of layout.

 
0
  #3
Dec 6th, 2004
Thats a fine idea, alas, one ive already tried with little success as the labels and sliders do not line up correctly - the labels end up being bunched together.

Thanks for the suggestion though
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 6,143
Reputation: jwenting is just really nice jwenting is just really nice jwenting is just really nice jwenting is just really nice 
Solved Threads: 213
Team Colleague
jwenting's Avatar
jwenting jwenting is offline Offline
duckman

Re: Choice of layout.

 
0
  #4
Dec 6th, 2004
hmm, I tried it and it looks fine.
I guess you used a different layout manager somewhere, probably a FlowLayout instead of a GridLayout...

By placing a gridlayout in each of the fields of the borderlayout they will line up correctly (as the vertical space taken up by each cell will be identical for all grid layouts in this case).
That will guarantee correct allignment as components are by default centered in a cell (or rather stretched to the entire cell size which in case of components with a fixed height like labels and sliders effectively centers them).

I noticed I forgot a few lines:
  1. jPanel1.setLayout(gridLayout1);
  2. jPanel2.setLayout(gridLayout2);
  3. jPanel3.setLayout(gridLayout3);
  4. gridLayout1.setRows(3);
  5. gridLayout2.setRows(3);
  6. gridLayout3.setRows(3);
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 89
Reputation: MrScruff is an unknown quantity at this point 
Solved Threads: 0
MrScruff's Avatar
MrScruff MrScruff is offline Offline
Junior Poster in Training

Re: Choice of layout.

 
0
  #5
Dec 6th, 2004
Hey you were right - not so sure what i did differently. mostlikely didn't give the label panes any sort of layout let alone a grid one.
ta muchly
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Java Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC