Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

swing question

  Asked By: Joel    Date: Sep 18    Category: Java    Views: 582
  

I am new to swing I am making a GUI, in which I have used a JTree placed on
BorderLayout.West , now I want to show different Components in
BorderLayout.Center depending on the node I select, these may be JTable,
JTextArea I have made all these componenets and Jtree listener but I am
unable to show components on center, how can i acheive this, so that I click
on node it shows the corresponding component and when I choose other node
the previous component should dissappear and new component should be
displayed.

Share: 

 

2 Answers Found

 
Answer #1    Answered By: Landra Schmidt     Answered On: Sep 18

you should use the following methods carefully.

-add(Component c)

-remove(Component c)

- doLayout()
- validate()



get sure that you call the "doLayout()" and
"validate()" methods of your container every time you
make a change in by adding and removing a component  to
your container.

 
Answer #2    Answered By: Alexander Bouchard     Answered On: Sep 18

I have written a sample program that may help you to understand how to do that thing that you wanted to do. I have added a new JPanel layed out by a CardLayout to the center  of the main frame and then used that panel to display different components  depending on the current tree selection.

The core functionality of the sample program lies in the addComponent, and the valueChanged methods. Take a careful look at them.

 
Didn't find what you were looking for? Find more on swing question Or get search suggestion and latest updates.




Tagged: