•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the Java section within the Software Development category of DaniWeb, a massive community of 391,706 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,293 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Java advertiser: Lunarpages Java Web Hosting
Views: 2975 | Replies: 1
![]() |
Is there anyway i can get some labels and sliders to alignproperly when they are both using grid layouts attached to a border layout.
Basically using one gridlayout for the lot meant that the labels had excessive space - so i opted for a border layout so the sizes would adjust accordingly. However this means the labels and sliders do not align.
Any suggestions?! Cheers
Ta Ta Mr Scruff
If someone could provide me with a means of a grid layout with automatically sized coloums that would be just as good.
Basically using one gridlayout for the lot meant that the labels had excessive space - so i opted for a border layout so the sizes would adjust accordingly. However this means the labels and sliders do not align.
Any suggestions?! Cheers

Ta Ta Mr Scruff
If someone could provide me with a means of a grid layout with automatically sized coloums that would be just as good.
•
•
Join Date: Nov 2004
Location: Netherlands
Posts: 5,646
Reputation:
Rep Power: 18
Solved Threads: 191
You will have to nest different layout managers.
Make a component that is a JPanel with a GridLayout containing a label and a slider (so 1 row of 2 columns).
Then add that to your borderlayout where you want it to appear.
That way it should line up as you wish.
A simple test yields this (note it will look a bit weird as I didn't try to constrain the horizontal allignment):
Make a component that is a JPanel with a GridLayout containing a label and a slider (so 1 row of 2 columns).
Then add that to your borderlayout where you want it to appear.
That way it should line up as you wish.
A simple test yields this (note it will look a bit weird as I didn't try to constrain the horizontal allignment):
public class TestLayout1 extends javax.swing.JFrame
{
/** Creates new form TestLayout1 */
public TestLayout1()
{
initComponents();
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
private void initComponents()
{
jPanel1 = new javax.swing.JPanel();
jLabel1 = new javax.swing.JLabel();
jSlider1 = new javax.swing.JSlider();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jPanel1.setLayout(new java.awt.GridLayout(1, 2));
jLabel1.setText("jLabel1");
jPanel1.add(jLabel1);
jPanel1.add(jSlider1);
getContentPane().add(jPanel1, java.awt.BorderLayout.NORTH);
pack();
}
/**
* @param args the command line arguments
*/
public static void main(String args[])
{
java.awt.EventQueue.invokeLater(new Runnable()
{
public void run()
{
new TestLayout1().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JLabel jLabel1;
private javax.swing.JPanel jPanel1;
private javax.swing.JSlider jSlider1;
// End of variables declaration
}![]() |
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
•
•
•
•
DaniWeb Java Marketplace
- Help! Can't browse, use control panel or Explorer (Viruses, Spyware and other Nasties)
- Intel mainboard D845HV, front panel configuration (Motherboards, CPUs and RAM)
- Drawing A Table On A Container(Panel) (Java)
- ActionListeners on the components of a panel (Java)
- Problems in Win98SE with Desktop Shortcuts and The Control Panel (Windows 9x / Me)
Other Threads in the Java Forum
- Previous Thread: palendromes with a string tokeniser
- Next Thread: How to print out the position of 2 dimension arrays?



Linear Mode