Java Reference
In-Depth Information
To use JLayer , first extend the javax.swing.plaf.LayerUI class, overrid-
ing various methods to customize painting and event handling. Continuing, pass an
instance of this class along with the component being decorated to the JLayer(V
view, LayerUI<V> ui) constructor( JLayer 'sgenerictypeis JLayer<V ex-
tends Component> ; LayerUI 'sgeneric typeis LayerUI<V extends Com-
ponent> .)
Thefirstargumentpassedtothisconstructoristhecomponentthatyouwanttodec-
orate, which is known as a view . The second argument identifies the decorator object.
The following excerpt from a revised version of Listing 7-6 shows you how to use
JLayer to add a translucent UNREGISTERED message over the center of Tem-
pVerter 's GUI:
public static void main(String[] args)
{
Runnable r = new Runnable()
{
@Override
public void run()
{
final
JFrame
f
=
new
JFrame("TempVerter");
f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
Border
b
=
BorderFact-
ory.createEmptyBorder(5, 5, 5, 5);
f.getRootPane().setBorder(b);
LayerUI<JPanel> layerUI;
layerUI = new LayerUI<JPanel>()
{
final Color PALE_BLUE = new Col-
or(0.0f, 0.0f,
1.0f,
0.1f);
final
Font
FONT
=
new
Font("Arial", Font.BOLD, 30);
final String MSG = "UNREGISTERED";
@Override
public
void
paint(Graphics
g,
Search WWH ::




Custom Search