Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have a JMenuBar and I have a JTabbedPane, when I create multiple tabs the JMenuBar does it on all the tabs, e.g. I open a file it opens the same file in each tab.

However I only want it to open a file on the current tab. I have added a ChangeListener so It know what tab its in however it does not seem help even though it works.

tabbedPane.addChangeListener(new ChangeListener() {
    public void stateChanged(ChangeEvent e) {
        System.out.println("Tab=" + tabbedPane.getSelectedIndex());
    }
});
getContentPane().add(tabbedPane, "Center");
pack();

I want to be able to have multiple tabs open while the menu bar only corresponds to current tab.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
151 views
Welcome To Ask or Share your Answers For Others

1 Answer

Let the object providing the content of each tab export it's own specific instances of Action. When the user changes tabs, use setAction() to set the desired action of each available JMenuItem in the global menu. There's a related example here.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...