0

我在框架中有一个菜单栏和一个选项卡式窗格,我希望如果我选择一个菜单项,那么请求的选项卡将打开。请帮我解决这个问题,谢谢!!!

4

2 回答 2

2

ActionListenerJMenuItem,可以调用JTabbedPane#setSelectedIndex

于 2012-06-30T07:27:50.560 回答
1

就像 SoboLAN 说的:

    final JTabbedPane tabs = new JTabbedPane();
    JPanel panel = new JPanel();
    tabs.add("title", panel);
    //add more tabs...

    // here the important part starts
    JMenuItem item = new JMenuItem("open tab 1");
    item.addActionListener(new ActionListener() {
        //this function get called when you click the item.
        @Override
        public void actionPerformed(ActionEvent e) {
            //insert the index you want to select
            tabs.setSelectedIndex(0);
        }
    });
于 2012-07-16T09:43:09.753 回答