I am using GridBagLayout as JFrame layout. My elements are not showing no matter what i write. Please don't give answers which use anything but GridBagLayout(sorry if it sound rude)
JPanel Panel;
JButton insertButton = new JButton("Insert");
GridBagConstraints gbc;
public MainFrame() {
this.setTitle("JAVA & MySQL");
this.setVisible(true);
this.setBounds(500, 100, 600, 600);
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
Panel = new JPanel(new GridBagLayout());
Panel.setOpaque(true);
Panel.setBackground(Color.BLUE);
gbc = new GridBagConstraints();
gbc.weightx = 1;
gbc.weighty = 1;
gbc.anchor = GridBagConstraints.CENTER;
gbc.gridx = 1;
gbc.gridy = 1;
gbc.insets = new Insets(0, 10, 0, 0);
gbc.fill = GridBagConstraints.BOTH;
Panel.add(insertButton, gbc);
}
See Question&Answers more detail:os