📄 jtabbedpane.java
字号:
* @param index The index to insert the tab at. * * @return The Component that was added. */ public Component add(Component component, int index) { if (component instanceof UIResource) super.add(component); else insertTab(component.getName(), null, component, null, index); return component; } /** * This method adds a tab to the JTabbedPane. If the Component is an * instance of UIResource, it doesn't add the tab and instead add the * component directly to the JTabbedPane. If the constraints object is an * icon, it will be used as the tab's icon. If the constraints object is a * string, we will use it as the title. * * @param component The associated component. * @param constraints The constraints object. */ public void add(Component component, Object constraints) { add(component, constraints, tabs.size()); } /** * This method adds a tab to the JTabbedPane. If the Component is an * instance of UIResource, it doesn't add the tab and instead add the * component directly to the JTabbedPane. If the constraints object is an * icon, it will be used as the tab's icon. If the constraints object is a * string, we will use it as the title. * * @param component The associated component. * @param constraints The constraints object. * @param index The index to insert the tab at. */ public void add(Component component, Object constraints, int index) { if (component instanceof UIResource) super.add(component); else { if (constraints instanceof String) insertTab((String) constraints, null, component, null, index); else insertTab(component.getName(), (constraints instanceof Icon) ? (Icon) constraints : null, component, null, index); } } /** * Removes the tab at index. After the component associated with * index is removed, its visibility is reset to true to ensure it * will be visible if added to other containers. * * @param index The index of the tab to remove. */ public void removeTabAt(int index) { checkIndex(index, 0, tabs.size()); tabs.remove(index); getComponentAt(index).show(); } /** * Removes the specified Component from the JTabbedPane. * * @param component The Component to remove. */ public void remove(Component component) { super.remove(component); } /** * Removes the tab and component which corresponds to the specified index. * * @param index The index of the tab to remove. */ public void remove(int index) { remove(getComponentAt(index)); removeTabAt(index); } /** * This method removes all tabs and associated components from the * JTabbedPane. */ public void removeAll() { for (int i = tabs.size() - 1; i >= 0; i--) removeTabAt(i); } /** * This method returns how many tabs are in the JTabbedPane. * * @return The number of tabs in the JTabbedPane. */ public int getTabCount() { return tabs.size(); } /** * This method returns the number of runs used to paint the JTabbedPane. * * @return The number of runs. */ public int getTabRunCount() { return ((TabbedPaneUI) ui).getTabRunCount(this); } /** * This method returns the tab title given the index. * * @param index The index of the tab. * * @return The title for the tab. */ public String getTitleAt(int index) { checkIndex(index, 0, tabs.size()); return ((Page) tabs.elementAt(index)).getTitle(); } /** * This method returns the active icon given the index. * * @param index The index of the tab. * * @return The active icon for the tab. */ public Icon getIconAt(int index) { checkIndex(index, 0, tabs.size()); return ((Page) tabs.elementAt(index)).getIcon(); } /** * This method returns the disabled icon given the index. * * @param index The index of the tab. * * @return The disabled icon for the tab. */ public Icon getDisabledIconAt(int index) { checkIndex(index, 0, tabs.size()); return ((Page) tabs.elementAt(index)).getDisabledIcon(); } /** * This method returns the tooltip string for the tab. * * @param index The index of the tab. * * @return The tooltip string for the tab. */ public String getToolTipTextAt(int index) { checkIndex(index, 0, tabs.size()); return ((Page) tabs.elementAt(index)).getTip(); } /** * This method returns the foreground color for the tab. * * @param index The index of the tab. * * @return The foreground color for the tab. */ public Color getForegroundAt(int index) { checkIndex(index, 0, tabs.size()); return ((Page) tabs.elementAt(index)).getForeground(); } /** * This method returns the background color for the tab. * * @param index The index of the tab. * * @return The background color for the tab. */ public Color getBackgroundAt(int index) { checkIndex(index, 0, tabs.size()); return ((Page) tabs.elementAt(index)).getBackground(); } /** * This method returns the component associated with the tab. * * @param index The index of the tab. * * @return The component associated with the tab. */ public Component getComponentAt(int index) { checkIndex(index, 0, tabs.size()); return ((Page) tabs.elementAt(index)).getComponent(); } /** * This method returns whether this tab is enabled. Disabled tabs cannot be * selected. * * @param index The index of the tab. * * @return Whether the tab is enabled. */ public boolean isEnabledAt(int index) { checkIndex(index, 0, tabs.size()); return ((Page) tabs.elementAt(index)).isEnabled(); } /** * This method returns the mnemonic for the tab. * * @param tabIndex The index of the tab. * * @return The mnemonic for the tab. */ public int getMnemonicAt(int tabIndex) { checkIndex(tabIndex, 0, tabs.size()); return ((Page) tabs.elementAt(tabIndex)).getMnemonic(); } /** * This method returns the mnemonic index for the tab. * * @param tabIndex The index of the tab. * * @return The mnemonic index for the tab. */ public int getDisplayedMnemonicIndexAt(int tabIndex) { checkIndex(tabIndex, 0, tabs.size()); return ((Page) tabs.elementAt(tabIndex)).getDisplayedMnemonicIndex(); } /** * This method returns the bounds of the tab given the index. * * @param index The index of the tab. * * @return A rectangle describing the bounds of the tab. */ public Rectangle getBoundsAt(int index) { checkIndex(index, 0, tabs.size()); return ((TabbedPaneUI) ui).getTabBounds(this, index); } /** * This method sets the title of the tab. * * @param index The index of the tab. * @param title The new title. */ public void setTitleAt(int index, String title) { checkIndex(index, 0, tabs.size()); ((Page) tabs.elementAt(index)).setTitle(title); } /** * This method sets the icon of the tab. * * @param index The index of the tab. * @param icon The new icon. */ public void setIconAt(int index, Icon icon) { checkIndex(index, 0, tabs.size()); ((Page) tabs.elementAt(index)).setIcon(icon); } /** * This method sets the disabled icon of the tab. * * @param index The index of the tab. * @param disabledIcon The new disabled icon. */ public void setDisabledIconAt(int index, Icon disabledIcon) { checkIndex(index, 0, tabs.size()); ((Page) tabs.elementAt(index)).setDisabledIcon(disabledIcon); } /** * This method sets the tooltip text of the tab. * * @param index The index of the tab. * @param toolTipText The tooltip text. */ public void setToolTipTextAt(int index, String toolTipText) { checkIndex(index, 0, tabs.size()); ((Page) tabs.elementAt(index)).setTip(toolTipText); } /** * This method sets the background color of the tab. * * @param index The index of the tab. * @param background The background color of the tab. */ public void setBackgroundAt(int index, Color background) { checkIndex(index, 0, tabs.size()); ((Page) tabs.elementAt(index)).setBackground(background); } /** * This method sets the foreground color of the tab. * * @param index The index of the tab. * @param foreground The foreground color of the tab. */ public void setForegroundAt(int index, Color foreground) { checkIndex(index, 0, tabs.size()); ((Page) tabs.elementAt(index)).setForeground(foreground); } /** * This method sets whether the tab is enabled. * * @param index The index of the tab. * @param enabled Whether the tab is enabled. */ public void setEnabledAt(int index, boolean enabled) { checkIndex(index, 0, tabs.size()); ((Page) tabs.elementAt(index)).setEnabled(enabled); } /** * This method sets the component associated with the tab. * * @param index The index of the tab. * @param component The component associated with the tab. */ public void setComponentAt(int index, Component component) { checkIndex(index, 0, tabs.size()); ((Page) tabs.elementAt(index)).setComponent(component); } /** * This method sets the displayed mnemonic index of the tab. * * @param tabIndex The index of the tab. * @param mnemonicIndex The mnemonic index. */ public void setDisplayedMnemonicIndexAt(int tabIndex, int mnemonicIndex) { checkIndex(tabIndex, 0, tabs.size()); ((Page) tabs.elementAt(tabIndex)).setDisplayedMnemonicIndex(mnemonicIndex); } /** * This method sets the mnemonic for the tab. * * @param tabIndex The index of the tab. * @param mnemonic The mnemonic. */ public void setMnemonicAt(int tabIndex, int mnemonic) { checkIndex(tabIndex, 0, tabs.size()); ((Page) tabs.elementAt(tabIndex)).setMnemonic(mnemonic); } /** * This method finds the index of a tab given the title. * * @param title The title that belongs to a tab. * * @return The index of the tab that has the title or -1 if not found. */ public int indexOfTab(String title) { int index = -1; for (int i = 0; i < tabs.size(); i++) { if (((Page) tabs.elementAt(i)).getTitle().equals(title)) { index = i; break; } } return index; } /** * This method finds the index of a tab given the icon. * * @param icon The icon that belongs to a tab. * * @return The index of the tab that has the icon or -1 if not found. */ public int indexOfTab(Icon icon) { int index = -1; for (int i = 0; i < tabs.size(); i++) { if (((Page) tabs.elementAt(i)).getIcon() == icon) { index = i; break; } } return index; } /** * This method finds the index of a tab given the component. * * @param component A component associated with a tab. * * @return The index of the tab that has this component or -1 if not found. */ public int indexOfComponent(Component component) { int index = -1; for (int i = 0; i < tabs.size(); i++) { if (((Page) tabs.elementAt(i)).getComponent() == component) { index = i; break; } } return index; } /** * This method returns a tab index given an (x,y) location. The origin of * the (x,y) pair will be the JTabbedPane's top left position. The tab * returned will be the one that contains the point. This method is * delegated to the UI. * * @param x The x coordinate of the point. * @param y The y coordinate of the point. * * @return The index of the tab that contains the point. */ public int indexAtLocation(int x, int y) { return ((TabbedPaneUI) ui).tabForCoordinate(this, x, y); } /** * This method returns the tooltip text given a mouse event. * * @param event The mouse event. * * @return The tool tip text that is associated with this mouse event. */ public String getToolTipText(MouseEvent event) { int index = indexAtLocation(event.getX(), event.getY()); return ((Page) tabs.elementAt(index)).getTip(); } /** * This method returns a string representation of this JTabbedPane. It is * mainly used for debugging purposes. * * @return A string representation of this JTabbedPane. */ protected String paramString() { return "JTabbedPane"; } /** * DOCUMENT ME! * * @return DOCUMENT ME! */ public AccessibleContext getAccessibleContext() { if (accessibleContext == null) accessibleContext = new AccessibleJTabbedPane(); return accessibleContext; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -