我在一个框架中有一个菜单栏和一个标签式窗格,我希望如果我选择一个menuitem,那么将打开所请求的选项卡。请帮帮我,谢谢!
答案 0 :(得分:2)
在ActionListener
的{{1}}中,您可以拨打JTabbedPane#setSelectedIndex
。
答案 1 :(得分:1)
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);
}
});