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.

depending on the selection of the radio but<strong>to</strong>n in the Border Style<br />

panel.<br />

The TitledBorder can be mixed with other borders. To do so, simply<br />

create an instance of TitledBorder, and use the setBorder method <strong>to</strong><br />

embed a new border in TitledBorder.<br />

The MatteBorder can be used <strong>to</strong> display icons on the border, as shown<br />

in Figure 37.20b.<br />

Chapter Summary<br />

1. javax.swing.JRootPane is a lightweight container used behind the<br />

scenes by Swing's <strong>to</strong>p-level containers, such as JFrame, JApplet,<br />

and JDialog. javax.swing.JLayeredPane is a container that<br />

manages the optional menu bar and the content pane. The content<br />

pane is an instance of Container. By default, it is a JPanel<br />

with BorderLayout. This is the container where the user<br />

interface <strong>com</strong>ponents are added. To obtain the content pane in a<br />

JFrame or in a JApplet, use the getContentPane() method. You can<br />

set any instance of Container <strong>to</strong> be a new content pane using the<br />

setContentPane method.<br />

2. Every container has a layout manager that is responsible for<br />

arranging its <strong>com</strong>ponents. The container's setLayout method can<br />

be used <strong>to</strong> set a layout manager. Certain types of containers<br />

have default layout managers.<br />

3. The layout manager places the <strong>com</strong>ponents in accordance with its<br />

own rules and property settings, and with the constraints<br />

associated with each <strong>com</strong>ponent. Every layout manager has its own<br />

specific set of rules. Some layout managers have properties that<br />

can affect the sizing and location of the <strong>com</strong>ponents in the<br />

container.<br />

4. <strong>Java</strong> also supports absolute layout, which enables you <strong>to</strong> place<br />

<strong>com</strong>ponents at fixed locations. In this case, the <strong>com</strong>ponent must<br />

be placed using the <strong>com</strong>ponent's instance method setBounds()<br />

(defined in java.awt.Component). Absolute positions and sizes<br />

are fine if the application is developed and deployed on the<br />

same platform, but what looks fine on a development system may<br />

not look right on a deployment system on a different platform.<br />

To solve this problem, <strong>Java</strong> provides a set of layout managers<br />

that place <strong>com</strong>ponents in containers in a way that is independent<br />

of fonts, screen resolutions, and operating systems.<br />

5. In addition <strong>to</strong> the layout managers provided in <strong>Java</strong>, you can<br />

create cus<strong>to</strong>m layout managers by implementing the LayoutManager<br />

interface.<br />

6. <strong>Java</strong> provides specialized containers Box, JScrollPane,<br />

JTabbedPane, and JSplitPane with fixed layout managers.<br />

7. A Swing border is defined in the Border interface. Every<br />

instance of JComponent can set a border through the border<br />

property defined in JComponent. If a border is present, it<br />

replaces the inset. There are eight concrete border classes:<br />

BevelBorder, SoftBevelBorder, CompoundBorder, EmptyBorder,<br />

EtchedBorder, LineBorder, MatteBorder, and TitledBorder. You can<br />

use the construc<strong>to</strong>rs of these classes or the static methods in<br />

javax.swing.BorderFac<strong>to</strong>ry <strong>to</strong> create borders.<br />

Test Questions<br />

39

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

Saved successfully!

Ooh no, something went wrong!