I want to add a JButton to a JPanel after a click on a button so here is my code :
JButton testButton = null;
private void sendmessageButtonActionPerformed(java.awt.event.ActionEvent evt) {
testButton = new JButton();
totalPane.add(testButton,BorderLayout.CENTER);
totalPane.revalidate();
totalPane.repaint();
}
I am using the Netbean GUI builder. When I click, nothing happens. Could anyone help me?
your code is correct for standard Swing JComponents,
1) is
totalPaneinitialized2) is
totalPaneadded to the Container3) is
totalPanevisible in the Container4) is there BorderLayout defined for
totalPane, othervise is there FlowLayout by defaultyou can simply to test it by add Borders (
totalPane.setBorder(BorderFactory.createLineBorder(Color.red));) to thetotalPane