19.09.2015 Views

Prentice.Hall.Introduction.to.Java.Programming,.Brief.Version.9th.(2014).[sharethefiles.com]

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

given title and/or icon. Figure 37.14 shows the frequently used<br />

properties, construc<strong>to</strong>rs, and methods in JTabbedPane.<br />

javax.swing.JComponent<br />

javax.swing.JTabbedPane<br />

#tabPlacement: int<br />

#selectedComponent: Component<br />

#selectedIndex: int<br />

+JTabbedPane()<br />

+JTabbedPane(tabPlacement: int)<br />

+getIconAt(index: int): Icon<br />

+setIconAt(index: int, icon: Icon): void<br />

+getTabCount(): int<br />

+getTitleAt(int index) : String<br />

+setTitleAt(index: int, title: String): void<br />

+getToolTipTextAt(index: int): String<br />

+setToolTipTextAt(index: int, <strong>to</strong>olTipText:<br />

String): void<br />

+indexOfComponent(<strong>com</strong>ponent:<br />

Component): void<br />

+indexOfTab(icon: Icon): int<br />

+indexOfTab(title: String): int<br />

<strong>Java</strong>Beans properties with get and set<br />

methods omitted in the UML diagram.<br />

The tab placement for this tabbed pane. Possible values are:<br />

JTabbedPane.TOP, JTabbedPane.BOTTOM, JTabbedPane.LEFT,<br />

and JTabbedPane.RIGHT (default: JTabbedPane.TOP).<br />

The currently selected <strong>com</strong>ponent for this tabbed pane.<br />

The currently selected index for this tabbed pane.<br />

Constructs a JTabbedPane with default tab placement.<br />

Constructs a JTabbedPane with the specified tab placement.<br />

Returns the icon at the specified tab index.<br />

Sets the icon at the specified tab index.<br />

Returns the number of tabs in this tabbed pane.<br />

Returns the tab title at the specified tab index.<br />

Sets the tab title at the specified tab index.<br />

Returns the <strong>to</strong>ol tip text at the specified tab index.<br />

Sets the <strong>to</strong>ol tip text at the specified tab index.<br />

Returns the index of the tab for the specified <strong>com</strong>ponent.<br />

Returns the index of the tab for the specified icon.<br />

Returns the index of the tab for the specified title.<br />

Figure 37.14<br />

JTabbedPane provides methods for displaying and manipulating the<br />

<strong>com</strong>ponents in the tabbed pane.<br />

Listing 37.7 gives an example that uses a tabbed pane with four tabs<br />

<strong>to</strong> display four types of figures: line, rectangle, rounded rectangle,<br />

and oval. You can select a figure <strong>to</strong> display by clicking the<br />

corresponding tab, as shown in Figure 37.13. The FigurePanel class for<br />

displaying a figure was presented in Listing 15.3, FigurePanel.java.<br />

You can use the type property <strong>to</strong> specify a figure type.<br />

Listing 37.7 DisplayFigure.java<br />

<br />

<br />

<br />

<br />

<br />

1 import java.awt.*;<br />

2 import javax.swing.*;<br />

3<br />

4 public class DisplayFigure extends JApplet {<br />

5 private JTabbedPane jtpFigures = new JTabbedPane();<br />

6 private FigurePanel squarePanel = new FigurePanel();<br />

7 private FigurePanel rectanglePanel = new FigurePanel();<br />

8 private FigurePanel circlePanel = new FigurePanel();<br />

9 private FigurePanel ovalPanel = new FigurePanel();<br />

10<br />

26

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!