e833. getting the tabs in a jtabbedpane container.txt

来自「这里面包含了一百多个JAVA源文件」· 文本 代码 · 共 46 行

TXT
46
字号
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 + =
减小字号Ctrl + -
显示快捷键?