Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

showing and hiding multiple components

 
Muhammad Qureshi
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,
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.
regards
Qureshi.
 
Chantal Ackermann
Ranch Hand
Posts: 508
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can use a CardLayout to switch between components. This should work fine. See the API documentation and the Swing tutorial for detailed information. You might also want to use a JSplitPane instead of a simple JPanel, so that the user can change the width of the JTree component.
After resetting a component you have to call revalidate or repaint on it, to cause the jvm to refresh the graphics.
Be sure to call all painting methods inside the event dispatching thread, using SwingUtilities.invokeLater or SwingUtilities.invokeAndWait.
chantal
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!