Example usage for javax.swing JTabbedPane setUI

List of usage examples for javax.swing JTabbedPane setUI

Introduction

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

Prototype

@BeanProperty(hidden = true, visualUpdate = true, description = "The UI object that implements the tabbedpane's LookAndFeel")
public void setUI(TabbedPaneUI ui) 

Source Link

Document

Sets the UI object which implements the L&F for this component.

Usage

From source file:Main.java

public static void main(String[] args) throws Exception {
    JTabbedPane pane = new JTabbedPane();
    pane.setUI(new SpacedTabbedPaneUI());
    pane.addTab("One", new JPanel());
    pane.addTab("Two", new JPanel());
    pane.addTab("Threeeeeee", new JPanel());
    pane.addTab("Four", new JPanel());

    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.add(pane);/*  ww  w. j  a  v a2s  .  com*/
    frame.setSize(500, 200);
    frame.setLocationRelativeTo(null);
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {
    JTabbedPane tabbedPane = new JTabbedPane();
    tabbedPane.setUI(new MetalTabbedPaneUI() {
        @Override/*from  w  ww  .  jav  a2  s. co  m*/
        protected int calculateTabWidth(int tabPlacement, int tabIndex, FontMetrics metrics) {
            int width = super.calculateTabWidth(tabPlacement, tabIndex, metrics);
            int extra = tabIndex * 50;
            return width + extra;
        }
    });
    tabbedPane.addTab("JTable", new JScrollPane(new JTable(5, 5)));
    tabbedPane.addTab("JTree", new JScrollPane(new JTree()));
    tabbedPane.addTab("JSplitPane", new JSplitPane());

    JPanel p = new JPanel();
    p.add(tabbedPane);

    JFrame frame = new JFrame();
    frame.setContentPane(p);
    frame.pack();
    frame.setVisible(true);
}

From source file:Main.java

public JComponent makeUI() {
    JTabbedPane tabbedPane = new JTabbedPane(JTabbedPane.TOP, JTabbedPane.SCROLL_TAB_LAYOUT);
    tabbedPane.setUI(new javax.swing.plaf.basic.BasicTabbedPaneUI() {
        @Override//w  w w .  j  a v  a 2 s .c o  m
        protected int calculateTabHeight(int tabPlacement, int tabIndex, int fontHeight) {
            return 32;
        }

        @Override
        protected void paintTab(Graphics g, int tabPlacement, Rectangle[] rects, int tabIndex,
                Rectangle iconRect, Rectangle textRect) {
            if (tabIndex == 0) {
                rects[tabIndex].height = 30 + 1;
                rects[tabIndex].y = 32 - rects[tabIndex].height + 1;
            } else if (tabIndex == 1) {
                rects[tabIndex].height = 26 + 1;
                rects[tabIndex].y = 32 - rects[tabIndex].height + 1;
            }
            super.paintTab(g, tabPlacement, rects, tabIndex, iconRect, textRect);
        }
    });
    tabbedPane.addTab("000", new JLabel("ok"));
    tabbedPane.addTab("111", new JScrollPane(new JTable()));
    tabbedPane.addTab("222", new JSplitPane());

    return tabbedPane;
}

From source file:net.pms.newgui.LooksFrame.java

public JComponent buildMain() {
    final JTabbedPane tabbedPane = new JTabbedPane(SwingConstants.TOP);

    tabbedPane.setUI(new CustomTabbedPaneUI());

    st = new StatusTab(configuration);
    tt = new TracesTab(configuration, this);
    gt = new GeneralTab(configuration, this);
    nt = new NavigationShareTab(configuration, this);
    tr = new TranscodingTab(configuration, this);
    ht = new HelpTab();

    tabbedPane.addTab(Messages.getString("LooksFrame.18"), st.build());
    tabbedPane.addTab(Messages.getString("LooksFrame.19"), tt.build());
    tabbedPane.addTab(Messages.getString("LooksFrame.20"), gt.build());
    tabbedPane.addTab(Messages.getString("LooksFrame.22"), nt.build());
    if (!configuration.isDisableTranscoding()) {
        tabbedPane.addTab(Messages.getString("LooksFrame.21"), tr.build());
    } else {/*w  w w .j  ava 2 s .c  o  m*/
        tr.build();
    }
    tabbedPane.addTab(Messages.getString("LooksFrame.24"), new HelpTab().build());
    tabbedPane.addTab(Messages.getString("LooksFrame.25"), new AboutTab().build());

    tabbedPane.addChangeListener(new ChangeListener() {
        @Override
        public void stateChanged(ChangeEvent e) {
            int selectedIndex = tabbedPane.getSelectedIndex();

            if (HELP_PAGES[selectedIndex] != null) {
                PMS.setHelpPage(HELP_PAGES[selectedIndex]);

                // Update the contents of the help tab itself
                ht.updateContents();
            }
        }
    });

    tabbedPane.setBorder(new EmptyBorder(5, 5, 5, 5));

    /*
     * Set the orientation of the tabbedPane.
     * Note: Do not use applyComponentOrientation() here because it
     * messes with the layout of several tabs.
     */
    ComponentOrientation orientation = ComponentOrientation.getOrientation(PMS.getLocale());
    tabbedPane.setComponentOrientation(orientation);

    return tabbedPane;
}