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 :D

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. ;)

13 Years
Discussion Span
Last Post by jwenting

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):

public class TestLayout1 extends javax.swing.JFrame
	/** Creates new form TestLayout1 */
	public TestLayout1()
	/** 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();

        jPanel1.setLayout(new java.awt.GridLayout(1, 2));



        getContentPane().add(jPanel1, java.awt.BorderLayout.NORTH);

	 * @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
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.