Reputation: 864
I have the design as follows.
When i click visualize i get the scatter plot.
Now what i want to do is to change the graph when the
user click on tabs. I want each tab to handle different
graph .How can i do that?
The main problem is i am not being able to
add mouse click listener to add actions to each tab,
that is my problem. How can i do that?
Upvotes: 1
Views: 2309
Reputation: 1698
Tabs change without a mouse. Typically through program logic such as when the tabbed view first appears with a default selection or with keyboard mnemonics assigned to a tab. Adding a mouse listener would miss those cases.
As Stefan suggested add a Changelistener to the JTabbedPane and you will be notified no matter when or what causes the tabs to change.
tabbedPane.addChangeListener(new ChangeListener() {
public void stateChanged(ChangeEvent e) {
System.out.println("Tab index: " + tabbedPane.getSelectedIndex());
}
});
Example here.
To change your contextual view based on the tabbed selected (scatter plot) you can:
If the plot is the same yet the data changes then update the model behind the plot and refresh the plot view. API's with MVC patterns such as JFreeChart will allow you to do this.
If the plots or views are substantially different for each tab use a CardLayout to switch the plot views.
Upvotes: 2