Here you can find the source of getTabComponentIndex(JTabbedPane tbp, Component component)
Parameter | Description |
---|---|
tbp | tabbed pane |
component | component to find |
Parameter | Description |
---|---|
IllegalArgumentException | if component does not belong tothis tabbed pane |
public static int getTabComponentIndex(JTabbedPane tbp, Component component) throws IllegalArgumentException
//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"); } }