📄 e833. getting the tabs in a jtabbedpane container.txt
字号:
This example retrieves all the tabs in a tabbed pane:
// To create a tabbed pane, see e828 Creating a JTabbedPane Container
// Get number of tabs
int count = pane.getTabCount();
// Get the properties of each tab
for (int i=0; i<count; i++) {
// Get label
String label = pane.getTitleAt(i);
// Get icon
Icon icon = pane.getIconAt(i);
// Get tool tip
String tooltip = pane.getToolTipTextAt(i);
// Is enabled?
boolean enabled = pane.isEnabledAt(i);
// Get mnemonic
int keycode = pane.getMnemonicAt(i);
// Get component associated with tab
Component comp = pane.getComponentAt(i);
}
Most of the methods that allow the properties of a tab to be changed require the index of the tab. The index of a tab can change as tabs are added, removed, or moved. Here are three ways to retrieve the index of a tab when needed.
// Get the index of the first tab that matches a label
String label = "Tab Label";
int index = pane.indexOfTab(label);
// Get the index of the first tab that matches an icon; the supplied
// icon must be the same instance that was used to create the tab
index = pane.indexOfTab(icon);
// Get the index of the tab by matching the child component; the supplied
// component must be the same instance that was used to create the tab
index = pane.indexOfComponent(component);
if (index < 0) {
// The tab could not be found
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -