Reputation: 89
I'm having trouble making a JMenuItem
in one class pull up a JTree
from another class that would act as a Help
menu for a program I'm making. The main problem I'm having is calling the JTree
from the one class through an ActionListener
in the JMenuItem
's class.
Here's the code from the JMenuItem's class that I'm talking about:
/*pulls up help menu*/
JMenuItem item1 = new JMenuItem("Help Menu");
myMenu.add(item1);
item1.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent event){
**if(item1.isEnabled()){
sjt = new SampleJTree();
}**
}
});
As I stated before, I'm not sure how to bring a JTree via the bold section (i.e. I don't know what to put in the if statement check). Any direction to the solution would be much appreciated.
Upvotes: 0
Views: 198
Reputation: 205855
The tutorial article How to Use Trees includes examples that show how to construct a JTree
and make it visible. This example shows how to search a tree for a matching string and make the corresponding node visible.
Addendum: For reference, How to Use Actions offers a useful way to encapsulate the ActionListener
.
Upvotes: 2