Hi.. I have 3 JPanels. (one) JPanel contains the scrollpane and the (two) JPanel contains a JButton. I am adding (one) + (two) into (combine) JPanel and then adding to the frame.Now I am really having a hard time align the scrollpane and the Jbutton. scroll pane is coming squeezed in the center and the Jbutton is squeezing it by staying on the right hand side alongwith it. I tried many methods below commented but not able to set the location of JButton and size and position of scrollpane.
I want the scrollpane in the center and button on the buttom.

Can anybody suggest whats going wrong ?

JScrollPane scroll = new JScrollPane(table);
    Container contentPane = getContentPane();
    JButton button1 = new JButton("MyButton");
    JPanel one = new JPanel();
    one.add(scroll,BorderLayout.NORTH);
    JPanel two = new JPanel();
    two.add(button1);
    //two.setSize(new Dimension(800,200));
    //two.setPreferredSize(new Dimension(800, 200));
    //two.setBounds(0, 0, 0, 0);
    //two.setHorizontalAlignment(JButton.LEFT);
    //two.setLocation(0,100);

    one.setVisible(true);
    JPanel combine = new JPanel();
    combine.add(one);
    combine.add(two);
    getContentPane().add(combine);

Thanks

Are you wanting to stick with a certain layout? Or are you willing to try out other layouts? If you are, you could use a gridBagLayout and set the x and y weight to how you are wanting it to adjust.

I believe that will do what you are looking for, if I read you correctly

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.