简体   繁体   English

在Java的jtabbedpane的选项卡中添加鼠标单击侦听器

[英]Adding mouse click listener in tab in jtabbedpane in java

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? 我怎样才能做到这一点?

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. 由于斯特凡建议添加的ChangeListener到JTabbedPane中,您将无论何时或什么原因造成的标签更改通知。

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. 具有MVC模式(例如JFreeChart)的 API将允许您执行此操作。

  • If the plots or views are substantially different for each tab use a CardLayout to switch the plot views. 如果每个选项卡的图或视图实质上不同,请使用CardLayout切换图视图。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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