How do I programmatically select a tab of a JTabbedPane?
I want to go to another tab by clicking on "next tab" button, how should I do it?
Code :
public class test{
JTabbedPane tab;
public static void main(String[] args){
test ar = new test();
}
public test(){
JFrame frame = new JFrame();
tab = new JTabbedPane();
JEditorPane pane= new JEditorPane();
JEditorPane pane1= new JEditorPane();
tab.add(pane);
tab.add(pane1);
frame.add(tab, BorderLayout.CENTER);
JPanel panel = new JPanel();
JButton button = new JButton("next Tab");
button.addActionListener(new MyAction());
panel.add(button);
tab.add("next Tab", panel);
tab.add(pane1);
frame.setSize(400, 400);
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public class MyAction implements ActionListener{
public void actionPerformed(ActionEvent e){
String str = e.getActionCommand();
if(str.equals("next Tab")){
//????????;
}
}
}
}
Re: How do I programmatically select a tab of a JTabbedPane?
Re: How do I programmatically select a tab of a JTabbedPane?
thanks but I am a bit confused about using it. suppose I want to select the tab which contains pane1. how should I write the code while I have just one JTabbedPane??
Re: How do I programmatically select a tab of a JTabbedPane?