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

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()
	{
		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
	
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.