0

Ok, i will try to make this as clear as i can.

i have FrIndex with a layout like below. enter image description here

when i created an event where the first button is clicked, the Red Panel will be removed and replace with another panel that i have in the same package.

so this is my code.

void CallMocChiaKhoa() {
    pnMocChiaKhoa p = new pnMocChiaKhoa();
    pnMain.removeAll();
    pnMain.add(p);
    pnMain.validate();        
}

normally this code would work just perfectly fine..i did this before with another similar project.

can anyone help?

mKorbel
  • 109,525
  • 20
  • 134
  • 319
zBaoAnhLe
  • 253
  • 1
  • 6
  • 19
  • I think you should add the java tag. That would get your question more attention. – EnKrypt May 27 '13 at 13:48
  • i guess this is swing? can you share the code where you are attaching a listener? the code you pasted could mean anything.. – rethab May 27 '13 at 13:52
  • @rethab yes this is Swing, im using netbean 7.3, somehow it added another swingswing layout extension to my project ...my other project didnt have it, does it make any different becuz of this extra extension? – zBaoAnhLe May 27 '13 at 14:08
  • 2
    @zBaoAnhLe that depends on what you extension is doing to your project. Please try to make a: http://sscce.org/ – rethab May 27 '13 at 14:13
  • you may be missing a call to repaint(); – P. Lalonde May 27 '13 at 14:33

2 Answers2

2

You can use CardPanel for this, as suggested in this example. Each button's ActionListener would need to know the name of the card it's meant to show(). The name can be stored in a field, as shown here, or in the corresponding panel itself, using setName().

Community
  • 1
  • 1
trashgod
  • 203,806
  • 29
  • 246
  • 1,045
1

Yeah i figured it out...you just have to add in one more line:

pnMain.setLayout(new BorderLayout());
pnMain.removeAll();

and it work perfectly...thanks guys for your help! :)

zBaoAnhLe
  • 253
  • 1
  • 6
  • 19