![]() In the TabbedPaneDemo example, the fourth panel has a preferred width and height that are larger than those of the other panels. Similarly, the minimum size of the tabbed pane depends on the biggest minimum width and height of all its children. The preferred size of the tabbed pane is just big enough to display its tallest child at its preferred height, and its widest child at its preferred width. When building components to add to a tabbed pane, keep in mind that no matter which child of a tabbed pane is visible, each child gets the same amount of space in which to display itself. To switch to a specific tab programmatically, use the Often, a mnemonic uses a character in the tab's title that is then automatically underlined. For example, setMnemonicAt(3, KeyEvent.VK_4) makes '4' the mnemonic for the fourth tab (which is at index 3, since the indices start with 0) pressing Alt-4 makes the fourth tab's component appear. The setMnemonicAt method allows the user to switch to a specific tab using the keyboard. When the JTabbedPane object has the focus, the keyboard arrows can be used to switch from tab to tab. To switch to a specific tab, the user clicks it with the mouse. There are three ways to switch to specific tabs using GUI. Note that the addTab method does not allow index specification in this step. Another way to create a tab is to use the insertTab method, which lets you specify the index of the tab you're adding. Optionally, you can specify an icon and tool tip string. The addTab method has several forms, but they all use both a string title and the component to be displayed by the tab. tMnemonicAt(3, KeyEvent.VK_4) Īs the previous code shows, the addTab method handles the bulk of the work in setting up a tab in a tabbed pane. "Panel #4 (has a preferred size of 410 x 50).") JComponent panel3 = makeTextPanel("Panel #3") JComponent panel2 = makeTextPanel("Panel #2") JComponent panel1 = makeTextPanel("Panel #1") ![]() ImageIcon icon = createImageIcon("images/middle.gif") JTabbedPane tabbedPane = new JTabbedPane() The JTabbedPane object takes care of mouse and keyboard events for you. Note that no event-handling code is necessary. TabbedPaneDemo.java creates the tabbed pane in the previous example. You can change the tab placement to LEFT, RIGHT, TOP or BOTTOM by using the setTabPlacement method. The default tab placement is set to the TOP location, as shown above. ![]() It does not select a new tab.Īs the TabbedPaneDemo example shows, a tab can have a tool tip and a mnemonic, and it can display both text and an image. Note that clicking the arrow only reveals hidden tabs. Scroll arrows appear next to the tabs.Ĭlick the arrow to view one of the hidden tabs. Resize the dialog box by moving its left or right boundary so that tabs do not fit within the dialog. The tabbed pane displays the component corresponding to the tab.įor example, in the Java look and feel you can select the tab labeled "Tab 3" by typing Alt-3. As a convenience, you can specify tool tip text when you add a component to the tabbed pane. The tool tip associated with the tab appears. ![]() Alternatively, to compile and run the example yourself, consult the example index. Java™ Web Start ( download JDK 7 or later). Click the Launch button to run TabbedPaneDemo using.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |