List of usage examples for javax.swing JTabbedPane indexOfComponent
public int indexOfComponent(Component component)
From source file:Main.java
public static void main(String[] argv) throws Exception { JTabbedPane pane = new JTabbedPane(); JButton component = new JButton("button"); int index = pane.indexOfComponent(component); if (index < 0) { // The tab could not be found }// ww w .j a va2 s .c o m }
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.//from 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:it.unifi.rcl.chess.traceanalysis.gui.TracePanel.java
public void setTitle(String t) { JTabbedPane parent = ((JTabbedPane) getParent()); parent.setTitleAt(parent.indexOfComponent(TracePanel.this), t); }
From source file:it.unifi.rcl.chess.traceanalysis.gui.TracePanel.java
public void dispose() { JTabbedPane parent = ((JTabbedPane) getParent()); parent.removeTabAt(parent.indexOfComponent(this)); }
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)); }
From source file:jeplus.gui.EPlusEditorPanel.java
/** * Make changes to UI to notify content change * * @param contentchanged//from w ww .j a va 2 s.co m */ public final void notifyContentChange(boolean contentchanged) { if (contentchanged) { this.cmdSave.setEnabled(true); if (ContainerComponent instanceof Frame) { ((Frame) ContainerComponent).setTitle(getTitle() + "*"); } else if (ContainerComponent instanceof Dialog) { ((Dialog) ContainerComponent).setTitle(getTitle() + "*"); } else if (ContainerComponent instanceof JTabbedPane) { if (TabId > 0) { //((JTabbedPane)ContainerComponent).setTitleAt(getTabId(), getTitle() + "*"); JTabbedPane jtb = (JTabbedPane) ContainerComponent; jtb.setTitleAt(jtb.indexOfComponent(this), getTitle() + "*"); } } } else { this.cmdSave.setEnabled(false); if (ContainerComponent instanceof Frame) { ((Frame) ContainerComponent).setTitle(getTitle()); } else if (ContainerComponent instanceof Dialog) { ((Dialog) ContainerComponent).setTitle(getTitle()); } else if (ContainerComponent instanceof JTabbedPane) { if (TabId > 0) { //((JTabbedPane)ContainerComponent).setTitleAt(getTabId(), getTitle()); JTabbedPane jtb = (JTabbedPane) ContainerComponent; jtb.setTitleAt(jtb.indexOfComponent(this), getTitle()); } } } }
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); }/* w ww . ja va 2 s .c om*/ if (show) { tabbedPane.setSelectedComponent(component); } }