There is a class which extends JFrame
. then Further JFrame
have JPanel
named contentPane and this Jpanel contains 2 more jpanel. as Tree shown in picture.
I Want to Center that contentPane in JFrame
so that on changing size of JFrame
JPanel
(contentPane) will remain in center. I have tried with different Layouts
but did not come up with right one. is there any way ?
Full page picture is here
Code is this.
public class Purchases extends JFrame {
private JPanel contentPane;
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
Purchases frame = new Purchases();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 513, 438);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
setLocationRelativeTo(null);
JPanel panel = new JPanel();
panel.setBounds(10, 10, 477, 193);
contentPane.add(panel);
panel.setLayout(null);
JPanel panel_1 = new JPanel();
panel_1.setBounds(10, 214, 477, 174);
contentPane.add(panel_1);
panel_1.setLayout(null);
}
This code is Eclipse automatically generated. I did not find where the contentPane is added in JFrame.