Hi I have been using netbeans and the swing functions for a while now. I recently have added a JPanel to my J frame by just dragging and dropping. I have then also added a button. I wrote the following code trying to add text to the Panel when the button is clicked. Below is the code I have used.
public void addTextTry(){
JLabel l1 = new JLabel("The add method appends an element to an array.");
JLabel l2 = new JLabel("This inturn increases the arrays size.");
jPanel1.add(l1);
jPanel1.add(l2);
}
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
addTextTry();
}
I am not getting an error message and If i add anything else to the code like adding text to a textbox, this works. I have checked for silly mistakes such as having the names of the panel and button wrong but this is all correct. Can anyone see or suggest why the text is not appearing in the panel when the button is clicked?