Adding Control to JFrame
Hi,
I'd want to add a second button to my JFrame when the first button is pressed,
so in the eventhander of button 1 I put:
JButton btn = new JButton("button2");
this.getContentPane().add(btn);
where this is a class extending javax.swing.JFrame
nothing happens when i press the first button... I'm puzzled, this should be easy...
# 2
You usually need to make the JFrame repaint itself in order for new elements to become visible. Usually a pack() or invalidate() does the trick. Packing may resize the JFrame, however... Greets, Mike
# 5
> I've tried adding pack(), validate(), invalidate() but the button still doesn't show :s
Then you are still doing something wrong.
If you need further help then you need to create a [url http://homepage1.nifty.com/algafield/sscce.html]Short, Self Contained, Compilable and Executable, Example Program[/url] (SSCCE) that demonstrates the incorrect behaviour, because I can't guess exactly what you are doing based on the information provided.
Don't forget to use the [url http://forum.java.sun.com/help.jspa?sec=formatting]Code Formatting Tags[/url] so the posted code retains its original formatting.