Example usage for javax.swing JTabbedPane addTab

List of usage examples for javax.swing JTabbedPane addTab

Introduction

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

Prototype

public void addTab(String title, Component component) 

Source Link

Document

Adds a component represented by a title and no icon.

Usage

From source file:SwingDnDTest.java

public SwingDnDFrame() {
    setTitle("SwingDnDTest");
    JTabbedPane tabbedPane = new JTabbedPane();

    JList list = SampleComponents.list();
    tabbedPane.addTab("List", list);
    JTable table = SampleComponents.table();
    tabbedPane.addTab("Table", table);
    JTree tree = SampleComponents.tree();
    tabbedPane.addTab("Tree", tree);
    JFileChooser fileChooser = new JFileChooser();
    tabbedPane.addTab("File Chooser", fileChooser);
    JColorChooser colorChooser = new JColorChooser();
    tabbedPane.addTab("Color Chooser", colorChooser);

    final JTextArea textArea = new JTextArea(4, 40);
    JScrollPane scrollPane = new JScrollPane(textArea);
    scrollPane.setBorder(new TitledBorder(new EtchedBorder(), "Drag text here"));

    JTextField textField = new JTextField("Drag color here");
    textField.setTransferHandler(new TransferHandler("background"));

    tabbedPane.addChangeListener(new ChangeListener() {
        public void stateChanged(ChangeEvent e) {
            textArea.setText("");
        }//from  ww  w .ja  v  a 2 s  . c om
    });

    tree.setDragEnabled(true);
    table.setDragEnabled(true);
    list.setDragEnabled(true);
    fileChooser.setDragEnabled(true);
    colorChooser.setDragEnabled(true);
    textField.setDragEnabled(true);

    add(tabbedPane, BorderLayout.NORTH);
    add(scrollPane, BorderLayout.CENTER);
    add(textField, BorderLayout.SOUTH);
    pack();
}

From source file:TooManyTabs.java

public TooManyTabs() {
    super("Too Many Tabs Test");
    setSize(200, 200);//from  w ww.  j  a  v a2  s.  c om
    setDefaultCloseOperation(EXIT_ON_CLOSE);
    Container contents = getContentPane();

    JTabbedPane wrap = new JTabbedPane();
    JTabbedPane scroll = new JTabbedPane();
    scroll.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT);
    for (int i = 1; i < 24; i++) {
        String tab = "Tab #" + i;
        wrap.addTab(tab, new JLabel(tab));
        scroll.addTab(tab, new JLabel(tab));
    }
    JTabbedPane top = new JTabbedPane(JTabbedPane.RIGHT);
    top.addTab("Wrap Tabs", wrap);
    top.addTab("Scroll Tabs", scroll);
    contents.add(top);

    setVisible(true);
}

From source file:com.eviware.soapui.impl.rest.panels.resource.RestResourceDesktopPanel.java

private Component buildContent() {
    JTabbedPane tabs = new JTabbedPane();
    paramsTable = new RestParamsTable(getModelItem().getParams(), true, ParamLocation.RESOURCE, true, false);
    tabs.addTab("Resource Parameters", paramsTable);
    return UISupport.createTabPanel(tabs, false);
}

From source file:net.erdfelt.android.sdkfido.ui.SdkFidoFrame.java

private Component createBody() {
    Container body = new Container();

    body.setLayout(new GridBagLayout());
    JTabbedPane tabs = new JTabbedPane();

    tabs.addTab("SDKs", createSdkPanel());
    tabs.addTab("Work Dir", createWorkDirPanel());

    body.add(tabs, new GBC().fillWide().margin(5, 5, 5, 5).endRow());
    body.add(createConsolePane(), new GBC().fillBoth().margin(0, 5, 5, 5).weightTall(1.0).endBoth());

    return body;/*from w w  w . ja v  a 2 s.  c o m*/
}

From source file:compecon.dashboard.panel.AgentsPanel.java

public AgentsPanel() {

    this.setLayout(new BorderLayout());

    JTabbedPane jTabbedPane = new JTabbedPane();

    for (Currency currency : Currency.values()) {
        JPanel panelForCurrency = new JPanel();
        panelForCurrency.setLayout(new GridLayout(0, 2));
        jTabbedPane.addTab(currency.getIso4217Code(), panelForCurrency);

        panelForCurrency.setBackground(Color.lightGray);

        for (Class<? extends Agent> agentType : ApplicationContext.getInstance().getAgentFactory()
                .getAgentTypes()) {//from   w  ww.  j a va  2 s .  c o  m
            panelForCurrency.add(createAgentNumberPanel(currency, agentType));
        }
    }

    add(jTabbedPane, BorderLayout.CENTER);
}

From source file:de.unidue.inf.is.ezdl.gframedl.components.AboutDialog.java

private JPanel getContent() {
    JPanel panel = new JPanel(new GridBagLayout());

    JLabel iconLabel = new JLabel(new ImageIcon(Images.LOGO_EZDL_LARGE_SINGLE.getImage()));

    JTextArea licenseTextArea = new JTextArea(licenseText);
    licenseTextArea.setEditable(false);/*from  w  ww  . ja v a 2s . co m*/
    licenseTextArea.setLineWrap(true);
    licenseTextArea.setWrapStyleWord(true);
    licenseTextArea.setOpaque(false);
    licenseTextArea.setBorder(BorderFactory.createEmptyBorder());
    JScrollPane licenseScrollPane = new JScrollPane(licenseTextArea);

    JTable propertiesTable = new JTable(tableModel);
    propertiesTable.setBackground(Color.WHITE);
    propertiesTable.setShowGrid(false);
    JScrollPane propertiesScrollPane = new JScrollPane(propertiesTable);
    propertiesScrollPane.setBackground(Color.WHITE);
    propertiesScrollPane.getViewport().setBackground(Color.WHITE);

    JButton closeButton = new JButton(I18nSupport.getInstance().getLocString("ezdl.controls.close"));
    closeButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            dispose();
        }
    });

    JTabbedPane tabbedPane = new JTabbedPane();
    tabbedPane.addTab(I18nSupport.getInstance().getLocString("ezdl.licence"), licenseScrollPane);
    tabbedPane.addTab(I18nSupport.getInstance().getLocString("ezdl.properties"), propertiesScrollPane);
    tabbedPane.setBackground(Color.WHITE);

    GridBagConstraints c = new GridBagConstraints();
    c.gridx = 0;
    c.gridy = 0;
    c.insets = new Insets(0, 0, 0, 0);
    c.anchor = GridBagConstraints.CENTER;
    panel.add(iconLabel, c);

    c.gridx = 0;
    c.gridy = 1;
    c.weightx = 1;
    c.weighty = 1;
    c.anchor = GridBagConstraints.CENTER;
    c.fill = GridBagConstraints.BOTH;
    c.insets = new Insets(10, 20, 10, 20);
    panel.add(tabbedPane, c);

    c.gridy = 2;
    c.fill = GridBagConstraints.NONE;
    c.weighty = 0;
    c.insets = new Insets(0, 20, 10, 20);
    panel.add(closeButton, c);

    panel.setBackground(Color.WHITE);

    return panel;
}

From source file:it.iit.genomics.cru.igb.bundles.mi.business.MIWorker.java

/**
 * Adds a component to a JTabbedPane with a little close tab" button on the
 * right side of the tab./* www  .j a v  a  2  s  .co m*/
 *
 * @param tabbedPane
 *            the JTabbedPane
 * @param c
 *            any JComponent
 * @param title
 *            the title for the tab
 */
public static void addClosableTab(final JTabbedPane tabbedPane, final JComponent c, final String title) {
    // Add the tab to the pane without any label
    tabbedPane.addTab(null, c);
    int pos = tabbedPane.indexOfComponent(c);

    // Create a FlowLayout that will space things 5px apart
    FlowLayout f = new FlowLayout(FlowLayout.CENTER, 5, 0);

    // Make a small JPanel with the layout and make it non-opaque
    JPanel pnlTab = new JPanel(f);
    pnlTab.setOpaque(false);

    // Add a JLabel with title and the left-side tab icon
    JLabel lblTitle = new JLabel(title);

    // Create a JButton for the close tab button
    JButton btnClose = new JButton("x");
    // btnClose.setOpaque(false);
    int size = 17;
    btnClose.setPreferredSize(new Dimension(size, size));
    btnClose.setToolTipText("close this tab");
    // Make the button looks the same for all Laf's
    btnClose.setUI(new BasicButtonUI());
    // Make it transparent
    btnClose.setContentAreaFilled(false);
    // No need to be focusable
    btnClose.setFocusable(false);
    btnClose.setBorder(BorderFactory.createEtchedBorder());
    btnClose.setBorderPainted(false);
    // Making nice rollover effect
    // we use the same listener for all buttons
    btnClose.setRolloverEnabled(true);
    // Close the proper tab by clicking the button

    // Configure icon and rollover icon for button
    btnClose.setRolloverEnabled(true);

    // Set border null so the button doesnt make the tab too big
    btnClose.setBorder(null);
    // Make sure the button cant get focus, otherwise it looks funny
    btnClose.setFocusable(false);

    // Put the panel together
    pnlTab.add(lblTitle);
    pnlTab.add(btnClose);

    // Add a thin border to keep the image below the top edge of the tab
    // when the tab is selected
    pnlTab.setBorder(BorderFactory.createEmptyBorder(2, 0, 0, 0));
    // Now assign the component for the tab
    tabbedPane.setTabComponentAt(pos, pnlTab);

    // Add the listener that removes the tab
    ActionListener listener = new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            if (JOptionPane.showConfirmDialog(new JFrame(),
                    "Are you sure you want to remove this tab? All results will be lost!", "Remove tab",
                    JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
                tabbedPane.remove(c);
            }
        }
    };
    btnClose.addActionListener(listener);

    // Optionally bring the new tab to the front
    tabbedPane.setSelectedComponent(c);

}

From source file:BoxAlignmentDemo.java

public BoxAlignmentDemo() {
    super(new BorderLayout());
    JTabbedPane tabbedPane = new JTabbedPane();

    JPanel buttonRow = new JPanel();
    // Use default FlowLayout.
    buttonRow.add(createButtonRow(false));
    buttonRow.add(createButtonRow(true));
    tabbedPane.addTab("Altering alignments", buttonRow);

    JPanel labelAndComponent = new JPanel();
    // Use default FlowLayout.
    labelAndComponent.add(createLabelAndComponent(false));
    labelAndComponent.add(createLabelAndComponent(true));
    tabbedPane.addTab("X alignment mismatch", labelAndComponent);

    JPanel buttonAndComponent = new JPanel();
    // Use default FlowLayout.
    buttonAndComponent.add(createYAlignmentExample(false));
    buttonAndComponent.add(createYAlignmentExample(true));
    tabbedPane.addTab("Y alignment mismatch", buttonAndComponent);

    // Add tabbedPane to this panel.
    add(tabbedPane, BorderLayout.CENTER);
}

From source file:layout.BoxAlignmentDemo.java

public BoxAlignmentDemo() {
    super(new BorderLayout());
    JTabbedPane tabbedPane = new JTabbedPane();

    JPanel buttonRow = new JPanel();
    //Use default FlowLayout.
    buttonRow.add(createButtonRow(false));
    buttonRow.add(createButtonRow(true));
    tabbedPane.addTab("Altering alignments", buttonRow);

    JPanel labelAndComponent = new JPanel();
    //Use default FlowLayout.
    labelAndComponent.add(createLabelAndComponent(false));
    labelAndComponent.add(createLabelAndComponent(true));
    tabbedPane.addTab("X alignment mismatch", labelAndComponent);

    JPanel buttonAndComponent = new JPanel();
    //Use default FlowLayout.
    buttonAndComponent.add(createYAlignmentExample(false));
    buttonAndComponent.add(createYAlignmentExample(true));
    tabbedPane.addTab("Y alignment mismatch", buttonAndComponent);

    //Add tabbedPane to this panel.
    add(tabbedPane, BorderLayout.CENTER);
}

From source file:de.interactive_instruments.ShapeChange.UI.DefaultDialog.java

public void initialise(Converter c, Options o, ShapeChangeResult r, String m) {
    converter = c;/* w  w  w .  ja  v  a  2  s  .  co m*/
    options = o;
    result = r;
    mdl = m;

    // frame
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JComponent newContentPane = new JPanel(new BorderLayout());
    newContentPane.setOpaque(true);
    setContentPane(newContentPane);

    // pane
    JTabbedPane tabbedPane = new JTabbedPane();
    tabbedPane.addTab("Main options", createTab1());
    tabbedPane.addTab("Secondary options", createTab2());
    newContentPane.add(tabbedPane);

    // frame size
    int height = 480;
    int width = 720;

    pack();

    Insets fI = getInsets();
    setSize(width + fI.right + fI.left, height + fI.top + fI.bottom);
    Dimension sD = Toolkit.getDefaultToolkit().getScreenSize();
    setLocation((sD.width - width) / 2, (sD.height - height) / 2);
}