e833. 获得JTabbedPane中的卡片
This example retrieves all the tabs in a tabbed pane:
// To create a tabbed pane, see e828 创建JTabbedPane // 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 }
Related Examples |