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.

470 Chapter 12 GUI Basics<br />

horizontal alignment<br />

12.11.2 Alignments<br />

Horizontal alignment specifies how the icon and text are placed horizontally on a but<strong>to</strong>n. You can<br />

set the horizontal alignment using setHorizontalAlignment(int) with one of the five constants<br />

LEADING, LEFT, CENTER, RIGHT, or TRAILING, as shown in Figure 12.18. At present,<br />

LEADING and LEFT are the same, and TRAILING and RIGHT are the same. Future implementation<br />

may distinguish them. The default horizontal alignment is AbstractBut<strong>to</strong>n.CENTER.<br />

Horizontally left Horizontally center Horizontally right<br />

FIGURE 12.18<br />

You can specify how the icon and text are placed on a but<strong>to</strong>n horizontally.<br />

vertical alignment<br />

Vertical alignment specifies how the icon and text are placed vertically on a but<strong>to</strong>n. You<br />

can set the vertical alignment using setVerticalAlignment(int) with one of the three<br />

constants TOP, CENTER, or BOTTOM, as shown in Figure 12.19. The default vertical alignment<br />

is AbstractBut<strong>to</strong>n.CENTER.<br />

Vertically <strong>to</strong>p Vertically center Vertically bot<strong>to</strong>m<br />

FIGURE 12.19<br />

You can specify how the icon and text are placed on a but<strong>to</strong>n vertically.<br />

horizontal text position<br />

12.11.3 Text Positions<br />

Horizontal text position specifies the horizontal position of the text relative <strong>to</strong> the icon. You<br />

can set the horizontal text position using setHorizontalTextPosition(int) with one of<br />

the five constants LEADING, LEFT, CENTER, RIGHT, or TRAILING, as shown in Figure 12.20.<br />

At present, LEADING and LEFT are the same, and TRAILING and RIGHT are the same.<br />

Future implementation may distinguish them. The default horizontal text position is<br />

AbstractBut<strong>to</strong>n.RIGHT.<br />

Text positioned left Text positioned center Text positioned right<br />

FIGURE 12.20<br />

You can specify the horizontal position of the text relative <strong>to</strong> the icon.<br />

vertical text position<br />

Vertical text position specifies the vertical position of the text relative <strong>to</strong> the icon. You can<br />

set the vertical text position using setVerticalTextPosition(int) with one of the three

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

Saved successfully!

Ooh no, something went wrong!