| | |
Choice of layout.
![]() |
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
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
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
Swing UI design is often best done on a piece of paper using pencil and eraser.
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
Java Syntax (Toggle Plain Text)
contentPane = (JPanel) getContentPane(); contentPane.setLayout(borderLayout1); contentPane.add(jPanel1, java.awt.BorderLayout.CENTER); jPanel1.add(jSlider1); jPanel1.add(jSlider3); jPanel1.add(jSlider2); contentPane.add(jPanel2, java.awt.BorderLayout.WEST); jPanel2.add(jLabel4); jPanel2.add(jLabel6); jPanel2.add(jLabel5); contentPane.add(jPanel3, java.awt.BorderLayout.EAST); jPanel3.add(jLabel1); jPanel3.add(jLabel3); jPanel3.add(jLabel2);
Swing UI design is often best done on a piece of paper using pencil and eraser.
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
Thanks for the suggestion though
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:
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:
Java Syntax (Toggle Plain Text)
jPanel1.setLayout(gridLayout1); jPanel2.setLayout(gridLayout2); jPanel3.setLayout(gridLayout3); gridLayout1.setRows(3); gridLayout2.setRows(3); gridLayout3.setRows(3);
![]() |
Similar Threads
- Need help with T/F and Multiple Choice (Java)
- check my layout (Website Reviews)
- GridBag layout problems. (Java)
- Redesigned Forum layout (DaniWeb Community Feedback)
Other Threads in the Java Forum
- Previous Thread: i am getting error to run tomcat 4
- Next Thread: The World's Youngest IBM Certified J2EE Developer.
| Thread Tools | Search this Thread |
911 actionlistener addressbook android api append applet application array arrays automation binary blackberry block bluetooth character chat class client code component consumer csv database desktop developmenthelp eclipse error fractal ftp game givemetehcodez graphics gui html ide image integer j2me j2seprojects japplet java javaarraylist javac javaee javaprojects jni jpanel julia lego linked linux list loops mac map method methods mobile netbeans newbie number objects online oriented panel printf problem program programming project projects properties recursion replaydirector reporting researchinmotion rotatetext rsa scanner se server set singleton sms sort sql string swing test textfields threads time title tree tutorial-sample ubuntu update windows working






