简体   繁体   中英

Java: How to change content of JPanel according to choice a item menu or JTree node?

I'm a web developer and I'm new in Java and I want know how to change content of a JPanel when choice any node of JTree or any item of menu. Because I don't want display many windows when click in any option but will reload only part of the program as if it were an ajax call in Web.

IE I want to display different content in the JPanel according to the option chosen, but now how.

If you could give me some tips, items to use, a better option to do or some example, greatly appreciate.

If you're a web developer, then it should be simple, because it works in a similar way as in JavaScript: you need to register an event listener on the tree ( TreeSelectionListener ) and on the menu item ( ActionListener ). When the user selects a node or chooses the menu item, the event you're interested in (node selected, or action performed on the menu item) will be fired, your listener will be called, and this listener just needs to replace the panel content with the new one.

Read the tutorial about JTree and the tutorial about JMenu for more guidance.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM