JButton, QButtonUI Demo
What Is It
This demo features JButton configuration options and new QButtonUI implementations.
How To Use It
Use the "Configuration" panel to control the buttons in the "Example" panel.
The 5 QButtonUIs can be installed by calling:
button.setUI(new BevelButtonUI());
button.setUI(new GradientButtonUI());
button.setUI(new RecessedButtonUI());
button.setUI(new RoundRectButtonUI());
button.setUI(new SquareButtonUI());
All configuration controls have specific tooltips that describe what property they define.
How It Works
AquaButtonUI
If you're viewing this on Mac: the default ButtonUI is the AquaButtonUI. This demo shows off 3 special features of the AquaButtonUI:
- Button Type: Apple offers a few specific button types to choose from. There used to be more, and they used to have specific roles/usages. But now Apple has simpler guidelines, and for the most part they encourage you to just the default push button.
- Segment Position: If a button type supports segmented positions: then the demo includes three consecutive buttons "Left", "Middle", "Right". Segmented buttons are still often used in toolbars in Mac applications.
- Size Variant: these help shrink buttons ("regular", "small", "mini"). I don't have any examples handy that demonstrate whether Apple still encourages using this practice, though.
QButtonUI
This demo also includes five new UIs: BevelButtonUI, GradientButtonUI, RecessedButtonUI, RoundRectButtonUI, SquareButtonUI. These are all subclasses of the abstract QButtonUI class. QButtonUI subclasses include the following options:
- Segment Positions: these are similar to Apple's implementation. QButtonUIs also include vertical segment positions, although this is not included in the demo. (Because, really, who needs vertically segmented buttons?)
- Paint Stroke: these buttons are mostly rendered using a call to
Graphics2D.fill(shape) and a separate call to Graphics2D.draw(shape). This client property toggles off the Graphics2D.draw(..) instruction. (The AbstractButton.isContentAreaFilled() method is used to toggle the Graphics2D.fill(..) instruction.)
- Paint Focus: focus can be painted outside the button shape or inside the button shape. (And
AbstractButton.setFocusPainted(..) toggles the presence of a painted focus entirely.)
- Buttons can also be rendered as a circle. This option is intended to only be used for buttons with an icon and no text. For example: a help button or a play/pause button.
- QButtonUIs can be converted to QComboBoxUIs so your JComboBoxes can match your JButtons in appearance. QComboBoxes include Apple's concept of being a "Pop-Up" button vs being a "Pull-Down" button.
There is no "size variant" option, but you can manually change the corner radius size and font size of buttons tweak the size.
QButtonUIs are vector-based, so if you render them on high-resolution monitors or otherwise change their size they should scale well.