This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

showing and hiding multiple components  RSS feed

 
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
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!