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 に答える