The QPanelUI
is a PanelUI
that supports:
You can configure our own QPanelUI
by calling:
Color topColor = Color.lightGray; Color bottomColor = Color.gray; QPanelUI ui = QPanelUI(topColor, bottomColor); ui.setShadowSize(3); ui.setCalloutSize(5); ui.setCalloutType(QPanelUI.CalloutType.TOP_CENTER); myPanel.setUI(ui);
Or you can use a static helper method to use a generic out-of-the-box look:
/** * This returns a subtly off-white UI with rounded corners and a (even more * subtle) one-pixel gray border. */ public static QPanelUI createBoxUI(); /** * This returns a white UI with rounded corners, a small callout, and * shadow. */ public static QPanelUI createToolTipUI();
When a QPanelUI
is installed on a JPanel
it replaces the panel's Border
. This custom border is sized so it can accommodate the callouts, shadow, rounded corners, etc.
The border and the QPanelUI share the same renderer. When the border is rendered clipping is used to punch a hole in the middle of the Graphics, and when the QPanelUI is rendered clipping is used to strip away the border. So the panel and its border render the same elements twice with complementary clipping.
There are two additional criteria that guided the current implementation:
In this demo if you mouse over the preview: some markings appear to show the total width/height of the panel, and where the border starts/stops.
This is the third rewrite of a recurring pet project of mine: a simple, configurable good-looking panel L&F. The previous iteration included a more distinct look, but this implementation tries to lean towards aesthetics that better fit Flat 2.0 UIs. The callouts were added so this can accommodate popover and stylized tooltips.