create icons regular icon pressed icon rollover icon add a button 470 Chapter

Create icons regular icon pressed icon rollover icon

This preview shows page 10 - 13 out of 19 pages.

create icons regular icon pressed icon rollover icon add a button
Image of page 10
470 Chapter 12 GUI Basics 12.11.2 Alignments Horizontal alignment specifies how the icon and text are placed horizontally on a button. You can set the horizontal alignment using setHorizontalAlignment(int) with one of the five con- stants LEADING , LEFT , CENTER , RIGHT , or TRAILING , as shown in Figure 12.18. At present, LEADING and LEFT are the same, and TRAILING and RIGHT are the same. Future implementa- tion may distinguish them. The default horizontal alignment is AbstractButton.CENTER . horizontal alignment Vertical alignment specifies how the icon and text are placed vertically on a button. You can set the vertical alignment using setVerticalAlignment(int) with one of the three constants TOP , CENTER , or BOTTOM , as shown in Figure 12.19. The default vertical alignment is AbstractButton.CENTER . vertical alignment 12.11.3 Text Positions Horizontal text position specifies the horizontal position of the text relative to the icon. You can set the horizontal text position using setHorizontalTextPosition(int) with one of the five constants LEADING , LEFT , CENTER , RIGHT , or TRAILING , as shown in Figure 12.20. At present, LEADING and LEFT are the same, and TRAILING and RIGHT are the same. Future implementation may distinguish them. The default horizontal text position is AbstractButton.RIGHT . Vertical text position specifies the vertical position of the text relative to the icon. You can set the vertical text position using setVerticalTextPosition(int) with one of the three horizontal text position vertical text position Horizontally left Horizontally center Horizontally right F IGURE 12.18 You can specify how the icon and text are placed on a button horizontally. Vertically top Vertically center Vertically bottom F IGURE 12.19 You can specify how the icon and text are placed on a button vertically. Text positioned left Text positioned center Text positioned right F IGURE 12.20 You can specify the horizontal position of the text relative to the icon.
Image of page 11
12.12 JCheckBox 471 constants TOP , CENTER , or BOTTOM , as shown in Figure 12.21. The default vertical text posi- tion is AbstractButton.CENTER . 12.28 How do you create a button with the text OK? How do you change text on a button? How do you set an icon, a pressed icon, and a rollover icon in a button? 12.29 Given a JButton object jbtOK , write statements to set the button’s foreground to red , background to yellow , mnemonic to K , tool tip text to Click OK to pro- ceed , horizontal alignment to RIGHT , vertical alignment to BOTTOM , horizontal text position to LEFT , vertical text position to TOP , and icon text gap to 5 . 12.30 List at least five properties defined in the AbstractButton class. 12.12 JCheckBox To create a check box button, use the JCheckBox class. A toggle button is a two-state button like a light switch.
Image of page 12
Image of page 13

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture