Example usage for javax.swing JTabbedPane getTitleAt

List of usage examples for javax.swing JTabbedPane getTitleAt

Introduction

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

Prototype

public String getTitleAt(int index) 

Source Link

Document

Returns the tab title at index.

Usage

From source file:Main.java

public static void main(String[] argv) throws Exception {
    JTabbedPane pane = new JTabbedPane();
    int count = pane.getTabCount();
    for (int i = 0; i < count; i++) {
        String label = pane.getTitleAt(i);
        Icon icon = pane.getIconAt(i);
        String tooltip = pane.getToolTipTextAt(i);
        boolean enabled = pane.isEnabledAt(i);
        int keycode = pane.getMnemonicAt(i);
        Component comp = pane.getComponentAt(i);
    }/*from  w w w  .  j a  va2s.  c  o m*/
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    JTabbedPane pane = new JTabbedPane();
    int src = pane.getTabCount() - 1;
    int dst = 0;/*from   w ww.j  a va2 s  .com*/

    Component comp = pane.getComponentAt(src);
    String label = pane.getTitleAt(src);
    Icon icon = pane.getIconAt(src);
    Icon iconDis = pane.getDisabledIconAt(src);
    String tooltip = pane.getToolTipTextAt(src);
    boolean enabled = pane.isEnabledAt(src);
    int keycode = pane.getMnemonicAt(src);
    int mnemonicLoc = pane.getDisplayedMnemonicIndexAt(src);
    Color fg = pane.getForegroundAt(src);
    Color bg = pane.getBackgroundAt(src);

    pane.remove(src);

    pane.insertTab(label, icon, comp, tooltip, dst);

    pane.setDisabledIconAt(dst, iconDis);
    pane.setEnabledAt(dst, enabled);
    pane.setMnemonicAt(dst, keycode);
    pane.setDisplayedMnemonicIndexAt(dst, mnemonicLoc);
    pane.setForegroundAt(dst, fg);
    pane.setBackgroundAt(dst, bg);
}

From source file:TabSample.java

public static void main(String args[]) {
    JFrame frame = new JFrame("Tabbed Pane Sample");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JTabbedPane tabbedPane = new JTabbedPane();

    String titles[] = { "General", "Security", "Content", "Connection", "Programs", "Advanced" };
    for (int i = 0, n = titles.length; i < n; i++) {
        add(tabbedPane, titles[i]);/*w w  w .  j a va 2  s. co m*/
    }

    ChangeListener changeListener = new ChangeListener() {
        public void stateChanged(ChangeEvent changeEvent) {
            JTabbedPane sourceTabbedPane = (JTabbedPane) changeEvent.getSource();
            int index = sourceTabbedPane.getSelectedIndex();
            System.out.println("Tab changed to: " + sourceTabbedPane.getTitleAt(index));
        }
    };
    tabbedPane.addChangeListener(changeListener);
    frame.add(tabbedPane, BorderLayout.CENTER);
    frame.setSize(400, 150);
    frame.setVisible(true);
}

From source file:MainClass.java

public static void main(String args[]) throws Exception {
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JTabbedPane tabbedPane = new JTabbedPane();
    tabbedPane.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT);
    String titles[] = { "A", "B", "C", "D", "E", "F" };
    int mnemonic[] = { KeyEvent.VK_A, KeyEvent.VK_B, KeyEvent.VK_C, KeyEvent.VK_D, KeyEvent.VK_E,
            KeyEvent.VK_F };//from w  w w  .j  a v  a2  s  .  c  o  m
    for (int i = 0, n = titles.length; i < n; i++) {
        add(tabbedPane, titles[i], mnemonic[i]);
    }

    ChangeListener changeListener = new ChangeListener() {
        public void stateChanged(ChangeEvent changeEvent) {
            JTabbedPane sourceTabbedPane = (JTabbedPane) changeEvent.getSource();
            int index = sourceTabbedPane.getSelectedIndex();
            System.out.println("Tab changed to: " + sourceTabbedPane.getTitleAt(index));
        }
    };
    tabbedPane.addChangeListener(changeListener);

    frame.add(tabbedPane, BorderLayout.CENTER);
    frame.setSize(400, 150);
    frame.setVisible(true);

}

From source file:TabbedPaneSample.java

public static void main(String args[]) {
    String title = (args.length == 0 ? "Tabbed Pane Sample" : args[0]);
    JFrame frame = new JFrame(title);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JTabbedPane tabbedPane = new JTabbedPane();
    String titles[] = { "General", "Security", "Content", "Connection", "Programs", "Advanced" };
    for (int i = 0, n = titles.length; i < n; i++) {
        add(tabbedPane, titles[i]);/*from ww w .j  av  a2 s.  c  o  m*/
    }

    ChangeListener changeListener = new ChangeListener() {
        public void stateChanged(ChangeEvent changeEvent) {
            JTabbedPane sourceTabbedPane = (JTabbedPane) changeEvent.getSource();
            int index = sourceTabbedPane.getSelectedIndex();
            System.out.println("Tab changed to: " + sourceTabbedPane.getTitleAt(index));
        }
    };
    tabbedPane.addChangeListener(changeListener);

    Container contentPane = frame.getContentPane();
    contentPane.add(tabbedPane, BorderLayout.CENTER);
    frame.setSize(400, 150);
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {
    final JTabbedPane jTabbedPane = new JTabbedPane();
    jTabbedPane.addTab("Red", new JLabel("Roses"));
    jTabbedPane.addTab("Blue", new JLabel("Skies"));
    jTabbedPane.addTab("Green", new JLabel("Grass"));

    for (int i = 0; i < jTabbedPane.getTabCount(); i++) {
        final JLabel tabComponent = new JLabel(jTabbedPane.getTitleAt(i));

        tabComponent.addMouseMotionListener(new MouseMotionAdapter() {
            @Override/* ww  w  .j  a va  2 s.  c  o  m*/
            public void mouseDragged(MouseEvent e) {
                System.out.println("tabComponent dragging");
            }
        });

        tabComponent.addMouseListener(new MouseAdapter() {
            @Override
            public void mousePressed(MouseEvent e) {
                int x = tabComponent.getLocationOnScreen().x - jTabbedPane.getLocationOnScreen().x;
                int y = tabComponent.getLocationOnScreen().y - jTabbedPane.getLocationOnScreen().y;
                MouseEvent me = new MouseEvent((JLabel) e.getSource(), e.getID(), e.getWhen(), e.getModifiers(),
                        x, y, e.getLocationOnScreen().x, e.getLocationOnScreen().y, e.getClickCount(),
                        e.isPopupTrigger(), e.getButton());
                jTabbedPane.getMouseListeners()[0].mousePressed(me);
                System.out.println("tabComponent mousePressed e=" + e);
            }
        });
        jTabbedPane.setTabComponentAt(i, tabComponent);
    }
    JFrame jFrame = new JFrame();
    jFrame.add(jTabbedPane);
    jFrame.setSize(400, 500);
    jFrame.setVisible(true);
    jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}

From source file:Main.java

public static void main(String[] args) {
    JTabbedPane tab = new JTabbedPane();
    tab.addTab("A", new JPanel());
    tab.addTab("+", new JPanel());
    tab.getModel().addChangeListener(new ChangeListener() {
        private int lastSelected;
        private boolean ignore = false;

        @Override/*  w w w.j  a  va 2  s  .  com*/
        public void stateChanged(ChangeEvent e) {
            if (!ignore) {
                ignore = true;
                try {
                    int selected = tab.getSelectedIndex();
                    String title = tab.getTitleAt(selected);
                    if ("+".equals(title)) {
                        JPanel pane = new JPanel();
                        tab.insertTab("Tab" + (tab.getTabCount() - 1), null, pane, null, lastSelected + 1);
                        tab.setSelectedComponent(pane);
                    } else {
                        lastSelected = selected;
                    }
                } finally {
                    ignore = false;
                }
            }
        }
    });
    final JButton btn = new JButton("Add");
    btn.addActionListener(e -> System.out.println(tab.getTabCount()));

    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.add(tab);
    frame.add(btn, BorderLayout.SOUTH);
    frame.pack();
    frame.setVisible(true);
}

From source file:dr.app.bss.Utils.java

public static int getTabbedPaneComponentIndex(JTabbedPane tabbedPane, String title) {

    int index = -Integer.MAX_VALUE;

    int count = tabbedPane.getTabCount();
    for (int i = 0; i < count; i++) {
        if (tabbedPane.getTitleAt(i).toString().equalsIgnoreCase(title)) {
            index = i;/*from   w  w  w  . jav  a 2  s . c o  m*/
            break;
        } // END: title check

    } // END: i loop

    return index;
}

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 .j ava  2s.  c o  m*/
    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));
}

From source file:it.unifi.rcl.chess.traceanalysis.gui.TracePanel.java

public String getTitle() {
    JTabbedPane parent = ((JTabbedPane) getParent());
    return parent.getTitleAt(parent.indexOfComponent(TracePanel.this));
}