문제

I have a menu-bar and a tabbed pane in a frame, and i want that if i select a menuitem, then the requested tab will open. Please help me with this, thanks!!!

도움이 되었습니까?

해결책

In the ActionListener of the JMenuItem, you can call JTabbedPane#setSelectedIndex.

다른 팁

like SoboLAN said:

    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);
        }
    });
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top