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