Example usage for javax.swing JTabbedPane add

List of usage examples for javax.swing JTabbedPane add

Introduction

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

Prototype

public Component add(Component component) 

Source Link

Document

Adds a component with a tab title defaulting to the name of the component which is the result of calling component.getName.

Usage

From source file:Main.java

public static void main(String[] argv) throws Exception {
    JTabbedPane pane = new JTabbedPane();
    JButton component = new JButton("button");

    component.setName("Tab Label");
    pane.add(component);

}

From source file:course_generator.frmMain.java

/**
 * Add a tab to JTabbedPane. The icon is at the left of the text and there
 * some space between the icon and the label
 * // ww  w  .ja va  2  s. c o  m
 * @param tabbedPane
 *            JTabbedPane where we want to add the tab
 * @param tab
 *            Tab to add
 * @param title
 *            Title of the tab
 * @param icon
 *            Icon of the tab
 */
private void addTab(JTabbedPane tabbedPane, Component tab, String title, Icon icon) {
    tabbedPane.add(tab);

    // Create bespoke component for rendering the tab.
    javax.swing.JLabel lbl = new javax.swing.JLabel(title);
    lbl.setIcon(icon);

    // Add some spacing between text and icon, and position text to the RHS.
    lbl.setIconTextGap(5);
    lbl.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);

    tabbedPane.setTabComponentAt(tabbedPane.getTabCount() - 1, lbl);
}