Example usage for javax.swing JTabbedPane indexOfTabComponent

List of usage examples for javax.swing JTabbedPane indexOfTabComponent

Introduction

In this page you can find the example usage for javax.swing JTabbedPane indexOfTabComponent.

Prototype

public int indexOfTabComponent(Component tabComponent) 

Source Link

Document

Returns the index of the tab for the specified tab component.

Usage

From source file:components.ButtonTabComponent.java

public ButtonTabComponent(final JTabbedPane pane) {
    //unset default FlowLayout' gaps
    super(new FlowLayout(FlowLayout.LEFT, 0, 0));
    if (pane == null) {
        throw new NullPointerException("TabbedPane is null");
    }//from ww w. jav  a  2 s .com
    this.pane = pane;
    setOpaque(false);

    //make JLabel read titles from JTabbedPane
    JLabel label = new JLabel() {
        public String getText() {
            int i = pane.indexOfTabComponent(ButtonTabComponent.this);
            if (i != -1) {
                return pane.getTitleAt(i);
            }
            return null;
        }
    };

    add(label);
    //add more space between the label and the button
    label.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 5));
    //tab button
    JButton button = new TabButton();
    add(button);
    //add more space to the top of the component
    setBorder(BorderFactory.createEmptyBorder(2, 0, 0, 0));
}