Java Reference
In-Depth Information
JComponent c)
{
super.paint(g, c); // Paint the
view.
g.setColor(PALE_BLUE);
g.setFont(FONT);
int
w
=
g.getFontMetrics().stringWidth(MSG);
int
h
=
g.getFontMetrics().getHeight();
g.drawString(MSG,
(c.getWidth()-w)/2,
c.getHeight()/
2+h/4);
}
};
JLayer<JPanel> layer;
layer
=
new
JLayer-
<JPanel>(createGUI(), layerUI);
f.setContentPane(layer);
fixGUI(f.getContentPane());
f.pack();
f.setResizable(false);
f.setVisible(true);
}
};
EventQueue.invokeLater(r);
}
To create a decorator, you minimally override LayerUI 's void
paint(Graphics g, JComponent c) method. Thecomponent passedto c is
the view.
Thefirstpaintingstepistopainttheviewviathe super.paint(g, c); method
call. Anything painted in subsequent code appears over the view.
Continuing,apalebluecolorisinstalledvia setColor() .Thiscoloriscreatedvia
Color(0.0f, 0.0f, 1.0f, 0.1f) —the first three arguments represent red,
Search WWH ::




Custom Search