List of usage examples for javax.swing JTabbedPane setTabComponentAt
@BeanProperty(preferred = true, visualUpdate = true, description = "The tab component at the specified tab index.") public void setTabComponentAt(int index, Component component)
From source file:TabComponent.java
public static void main(String[] args) { JTabbedPane pane = new JTabbedPane(); String title = "Tab"; pane.add(title, new JLabel(title)); pane.setTabComponentAt(0, new TabComponent(title, pane)); JFrame frame = new JFrame("Tab Component Demo"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.add(pane);//from w ww . j a v a 2 s . co m frame.setSize(500, 200); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JTabbedPane tp = new JTabbedPane(); tp.addTab("Dates", new JPanel()); tp.addTab("Deliveries", new JPanel()); tp.addTab("Exports", new JPanel()); tp.setTabComponentAt(0, new JLabel("Dates")); tp.setTabComponentAt(1, new JLabel("Deliveries")); tp.setTabComponentAt(2, new JLabel("Exports")); JFrame frame = new JFrame("Testing"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setLayout(new BorderLayout()); frame.add(tp);// ww w . j a v a2 s. com frame.pack(); 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/* w w w.j a v a2s. 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:TabSample.java
static void addIt(JTabbedPane tabbedPane, String text) { JLabel label = new JLabel(text); JButton button = new JButton(text); JPanel panel = new JPanel(); panel.add(label);/* w w w . j a v a2 s. com*/ panel.add(button); tabbedPane.addTab(text, panel); tabbedPane.setTabComponentAt(tabbedPane.getTabCount() - 1, new JTextField(text)); }
From source file:Main.java
public Main() { Icon icon = UIManager.getIcon("html.pendingImage"); JTabbedPane jtb = new JTabbedPane(); JPanel jplInnerPanel1 = createInnerPanel("Tab 1: Tooltip and Icon"); jtb.addTab("One", icon, jplInnerPanel1, "Tab 1"); jtb.setSelectedIndex(0);/*from ww w . j a v a 2s .c o m*/ JPanel jplInnerPanel2 = createInnerPanel("Tab 2: Icon only"); jtb.addTab("Two", icon, jplInnerPanel2); JPanel jplInnerPanel3 = createInnerPanel("Tab 3: Tooltip and Icon"); jtb.addTab("Three", icon, jplInnerPanel3, "Tab 3"); JPanel jplInnerPanel4 = createInnerPanel("Tab 4: Text only"); jtb.addTab("Four", jplInnerPanel4); menu.add(new JMenuItem("Item 1")); menu.add(new JMenuItem("Item 2")); JLabel tab4Label = new JLabel(); tab4Label.setText("Four"); jtb.setTabComponentAt(3, tab4Label); tab4Label.addMouseListener(new MouseAdapter() { @Override public void mouseReleased(MouseEvent e) { maybeShowPopup(e); } @Override public void mousePressed(MouseEvent e) { maybeShowPopup(e); } private void maybeShowPopup(MouseEvent e) { jtb.getModel().setSelectedIndex(3); if (e.isPopupTrigger()) { menu.show(e.getComponent(), e.getX(), e.getY()); } } }); setLayout(new GridLayout()); add(jtb); }
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.// w w w .j a v a 2 s. com * * @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: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 * //from w ww . j a v a 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); }
From source file:pl.otros.logview.api.OtrosApplication.java
public void addClosableTab(String name, String tooltip, Icon icon, JComponent component, boolean show) { JTabbedPane tabbedPane = getJTabbedPane(); if (tabbedPane.indexOfComponent(component) == -1) { int tabCount = tabbedPane.getTabCount(); tabbedPane.addTab(name, icon, component); tabbedPane.setTabComponentAt(tabCount, new TabHeader(tabbedPane, name, icon, tooltip)); tabbedPane.setSelectedIndex(tabCount); }/*www.j a v a 2 s.c o m*/ if (show) { tabbedPane.setSelectedComponent(component); } }