Java JTabbedPane getTabComponentIndex(JTabbedPane tbp, Component component)

Here you can find the source of getTabComponentIndex(JTabbedPane tbp, Component component)

Description

Returns index of a tab's component inside tabbed pane

License

Open Source License

Parameter

Parameter Description
tbp tabbed pane
component component to find

Exception

Parameter Description
IllegalArgumentException if component does not belong tothis tabbed pane

Return

component's index

Declaration

public static int getTabComponentIndex(JTabbedPane tbp, Component component) throws IllegalArgumentException 

Method Source Code

//package com.java2s;
/*/*from w  ww.j  a va  2s  .c  om*/
 *   Swing Explorer. Tool for developers exploring Java/Swing-based application internals. 
 *     Copyright (C) 2012, Maxim Zakharenkov
 *
 *   This library is free software; you can redistribute it and/or
 *   modify it under the terms of the GNU Lesser General Public
 *   License as published by the Free Software Foundation; either
 *   version 2.1 of the License, or (at your option) any later version.
 *
 *   This library is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *   Lesser General Public License for more details.
 *
 *   You should have received a copy of the GNU Lesser General Public
 *   License along with this library; if not, write to the Free Software
 *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *   
 */

import java.awt.Component;

import javax.swing.JTabbedPane;

public class Main {
    /**
     * Returns index of a tab's component inside tabbed pane
     * @param tbp tabbed pane
     * @param component component to find
     * @return component's index
     * @throws IllegalArgumentException if component does not belong to
     * this tabbed pane
     */
    public static int getTabComponentIndex(JTabbedPane tbp, Component component) throws IllegalArgumentException {
        int count = tbp.getTabCount();
        for (int i = 0; i < count; i++) {
            if (component == tbp.getComponentAt(i)) {
                return i;
            }
        }
        throw new IllegalArgumentException("No component found in the tabbed pane");
    }
}

Related

  1. getNextSubTabIndex(JTabbedPane tabs, int tabIndex)
  2. getOffsetOfVirtualColumn(Segment seg, int tabSize, int column, int[] totalVirtualWidth)
  3. getParagraphStyle(SimpleAttributeSet attrSet, int align, float firstLineIndent, float leftIndent, float rightIndent, float lineSpace, float spaceAbove, float spaceBelow, TabSet tabs)
  4. getTabbedPaneComponentIndex(JTabbedPane tabbedPane, String title)
  5. getTabbedPaneFor(Component c)
  6. getTabIndex(final JTabbedPane tabs, final String title)
  7. getTabIndexAt(JTabbedPane tabbedPane, int x, int y)
  8. getTabPaneLeadingPlacement()
  9. getTabsHeight()