O'Reilly logo

Swing Hacks by Chris Adamson, Joshua Marinacci

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Create Custom Tool Tips #43
Chapter 6, Transparent and Animated Windows
|
227
HACK
jparent.setOpaque(false);
}
}
}
// ... the rest of the drawing code
Install the Tool Tip
To install the custom tool tip, you need to override the createToolTip( )
method of the component you wish to modify. An example using a custom
JButton
is shown in Example 6-5.
Because the tool tip is specified by the custom
JButton class, all you need to
do is create some components and set their tool tip text. The code in
Example 6-6 creates two buttons and three labels in a frame. The buttons
have custom tool tips that will display—complete with the now transparent
corners—on top of the rest of the screen, as shown in Figure 6-6.
Example 6-5. Installing a custom tool tip
class CustomJButton extends JButton {
JToolTip _tooltip;
public CustomJButton( ) {
_tooltip = new CustomToolTip( );
_tooltip.setComponent(this);
}
public JToolTip createToolTip( ) {
return _tooltip;
}
}
Figure 6-6. A tool tip with a custom border

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required