我想知道,是否有可能确定该用户是否留下了某些标签。例如,我们有2个标签:“omg”和“lol”。当前标签为omg。我想知道用户从“omg”切换为“lol”

最佳答案

通过将更改侦听器添加到JTabbedPane,您将知道选项卡选择何时更改。

更新:添加了选项卡索引跟踪

tabbedPane.getModel().addChangeListener(new ChangeListener() {
    int lastTabIndex = -1;
    public void stateChanged(ChangeEvent e) {
         int newIndex = tabbedPane.getSelectedIndex();
         if (lastTabIndex == 1 && newIndex == 2) { //or whatever check/combination of checks you would like
             //switched from tab 1 to tab 2!
         }

         //or just check for leaving tab 1
         if (lastTabIndex == 1) {
             //left tab 1!
         }

         //etc

         lastTabIndex = newIndex;
    }
});

07-25 21:04