Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: How do I programmatically select a tab of a JTabbedPane?

  1. #1
    Member
    Join Date
    Mar 2010
    Posts
    111
    Thanks
    19
    Thanked 0 Times in 0 Posts

    Default 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?

    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")){
     
          //????????;
     
          }
        }
      }
    }
    Last edited by nasi; April 12th, 2010 at 05:27 AM.


  2. #2
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,896
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default Re: How do I programmatically select a tab of a JTabbedPane?


  3. The Following User Says Thank You to helloworld922 For This Useful Post:

    nasi (April 14th, 2010)

  4. #3
    Member
    Join Date
    Mar 2010
    Posts
    111
    Thanks
    19
    Thanked 0 Times in 0 Posts

    Default 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??

  5. #4
    Member
    Join Date
    Mar 2010
    Posts
    111
    Thanks
    19
    Thanked 0 Times in 0 Posts

    Default Re: How do I programmatically select a tab of a JTabbedPane?

    I got it, thanks

Similar Threads

  1. select count(*)
    By jacinto in forum JDBC & Databases
    Replies: 4
    Last Post: March 2nd, 2010, 10:30 PM
  2. Get <SELECT> tag values on other jsp page
    By nehakuls in forum JavaServer Pages: JSP & JSTL
    Replies: 0
    Last Post: November 18th, 2009, 02:29 AM
  3. traversing multiple jTabbedPane?
    By dewboy3d in forum AWT / Java Swing
    Replies: 3
    Last Post: October 2nd, 2009, 07:26 PM

Tags for this Thread