So for the sake of simplicity I set up a little test code just to figure out this problem. Basically I have a JFrame
and I added 'this' to it (I just extended my main class from JComponent
to save time). this component fills in a red background. Then I have it sleep for 2 seconds and then type this.
f.remove(this);
thing t = new thing();
f.add(t);
f.setVisible(true);
f being my JFrame
object and 'thing' is just another class extending JComponent
that paints a blue background..
when I comment out setvisible()
it no longer changes to blue.. I've tried using t.setVisible(true) but it seems I have to make the frame visible again, not the component
does anyone know why I have to call that... or if there is another way to change components within a single frame?