Results 1 to 6 of 6

Thread: Confused about JTabbedPane class

  1. #1
    Join Date
    Dec 2009
    Posts
    32

    Confused about JTabbedPane class

    Hello Guys,

    I am beginner in the field of java programming language. The concept of 'java classes' seems very difficult as compare to C++ programming. I am getting troubled while understanding the JTabbedPane class of java. I want to know the use of JTabbedPane class as well as it's methods. If you have sound knowledge about the 'JTabbedPane class', then please let me know that. I am waiting for your reply.

  2. #2
    Join Date
    Apr 2008
    Posts
    2,005

    Re: Confused about JTabbedPane class

    A JTabbedPane class component that lets the user switch between a group of components by clicking on a tab with a given title and/or icon. Tabs/components are added to a TabbedPane object by using the addTab and insertTab methods. A tab is represented by an index corresponding to the position it was added in, where the first tab has an index equal to 0 and the last tab has an index equal to the tab count minus 1. The TabbedPane uses a SingleSelectionModel to represent the set of tab indices and the currently selected index.

  3. #3
    Join Date
    May 2008
    Posts
    2,297

    Re: Confused about JTabbedPane class

    Please refer following example of java , which will depict you the use of JTabbedPane class:
    Code:
    import javax.swing.JTabbedPane;
    
    public class JTabbedPaneDemo {
    
      static void add(JTabbedPane TBP, String lb, int mnemonic) {
        int count = TBP.getTabCount();
        JButton button = new JButton(lb);
        TBP.addTab(lb, new ImageIcon("yourFile.gif"), button, lb);
        TBP.setMnemonicAt(count, mnemonic);
      }
    
      public static void main(String args[]) {
        JFrame fmj = new JFrame("Tabbed Pane Sample");
        fmj.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    
        JTabbedPane TBP = new JTabbedPane();
        TBP.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT);
        String titles[] = { "General", "Security", "Content", "Connection", "Programs", "Advanced" };
        int mnemonic[] = { KeyEvent.VK_G, KeyEvent.VK_S, KeyEvent.VK_C, KeyEvent.VK_O, KeyEvent.VK_P,
            KeyEvent.VK_A };
        for (int i = 0, n = titles.length; i < n; i++) {
          add(TBP, titles[i], mnemonic[i]);
        }
    
        TBP.removeAll();
        fmj.add(TBP, BorderLayout.CENTER);
        fmj.setSize(500, 150);
        fmj.setVisible(true);
      }
    }

  4. #4
    Join Date
    May 2008
    Posts
    2,389

    Re: Confused about JTabbedPane class

    Hi friend,

    I suggest you to review following few methods of JTabbedPane class:
    • setToolTipTextAt(int indexVal, String TexttoolTip)
    • setTabLayoutPolicy(int tabLayout)
    • setIconAt(int index, Icon icn)
    • setDisplayedMnemonicIndexAt(int IndexodTab, int cIndex)
    • setComponentAt(int indexval, Component cmp)
    • removeTabAt(int indexVal)

  5. #5
    Join Date
    Feb 2008
    Posts
    1,852

    Re: Confused about JTabbedPane class

    Hi,

    Following java program is very good example of JTabbedPane class. In this program I have used 'getIconAt()' method of the JTabbedPane class.
    Code:
    import javax.swing.JTabbedPane;
    import java.awt.Component;
    import javax.swing.Icon;
    
    public class JTPane {
      public static void main(String[] argv) throws Exception {
        JTabbedPane pane1 = new JTabbedPane();
        int count = pane1.getTabCount();
        for (int il = 0; il < count; il++) {
          String label = pane1.getTitleAt(il);
          Icon icon = pane1.getIconAt(il);
          String tooltip = pane1.getToolTipTextAt(il);
          boolean enabled = pane1.isEnabledAt(il);
          int keycode = pane1.getMnemonicAt(il);
          Component comp = pane1.getComponentAt(il);
        }
      }
    }

  6. #6
    Join Date
    Jan 2008
    Posts
    1,521

    Re: Confused about JTabbedPane class

    Constructors of JTabbedPane class:
    1. JTabbedPane(int tabPlacementVal, int tabLayoutPolicyVal): This constructor of JTabbedPane class is essential for the creation of an TabbedPane which is empty.
    2. JTabbedPane(int tabPlacementVal): This constructor of JTabbedPane class is essential for the creation of TabbedPane along with the specified tab placement.
    3. JTabbedPane(): This constructor of JTabbedPane class is essential for creation of TabbedPane along with a default tab placement.

Similar Threads

  1. Where can I find Java 1.5 swing (JTabbedPane class) source code
    By Who is it in forum Software Development
    Replies: 5
    Last Post: 23-07-2010, 03:35 AM
  2. Confused with BorderFactory class
    By Sonam Goenka in forum Software Development
    Replies: 5
    Last Post: 20-02-2010, 02:42 PM
  3. Confused with DefaultListModel class
    By Khan Baba in forum Software Development
    Replies: 4
    Last Post: 19-02-2010, 12:29 PM
  4. Confused about JCheckBox class
    By Khan Baba in forum Software Development
    Replies: 5
    Last Post: 18-02-2010, 12:54 PM
  5. Confused with JInternalFrame class
    By Truster in forum Software Development
    Replies: 5
    Last Post: 17-02-2010, 09:58 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,584,848.05564 seconds with 17 queries