Problem regarding JPanel

i am using 3 JPanels in my prog. All are added to a JFrame , which contains 3 TollBarButtons. if i click on one toolbarbutton one Jpanel must appear. when making the JPanel visible i need to check which Jpnael is currently visible and make it hide.

How can it be possible?

Please send me the solution as quickly as possible.

thank u.

[360 byte] By [bhuvana] at [2007-10-2 18:21:04]
# 1
set the frame as a cardlayout, add your 3 panels, with identifiers "0" "1" and "2",then the code for each toolbar button would becardLayout.show(container, identifier)
Michael_Dunna at 2007-7-13 19:41:37 > top of Java-index,Desktop,Core GUI APIs...
# 2

Hi

Better way U set ur JFrame layout as BorderLayout.then u can set ur toolbar on the top of the JFrame

getContentPane().add(toolbar,BorderLayout.NORTH);

after that u can create 3 JPanels.

if u r clicking on first button u can add first Panel to the center of JFrame using following command

getContentPane().add(panel1,BorderLayout.CENTER);

in the same way u can add other Panels also.

before adding other Panel u have to check the other two panel objects is null or not.

before adding the JPanel object u have to set as null other two JPanel objects.

for example if u r clicking first button that time u have to set as null other two panel objects

regards

pradeep

Pradeep_M_Va at 2007-7-13 19:41:37 > top of Java-index,Desktop,Core GUI APIs...
# 3

> Better way U set ur JFrame layout as BorderLayout.then u can set ur toolbar

> on the top of the JFrame

Yep, forgot about the toolbar, but a cardlayout is still the easiest option -

add a panel (cardlayout) to the frame, then add the other 3 panels to the

cardlayout panel

Michael_Dunna at 2007-7-13 19:41:37 > top of Java-index,Desktop,Core GUI APIs...