Java Reference
In-Depth Information
should getPreferredSize()
// be called more than
// perform other initialization (such as registering
a mouse listener) here
public Dimension getPreferredSize()
return d;
public void paint(Graphics g)
// perform painting here
It is often not a good idea to override paint() in the context of Swing because
JComponent overridesthismethodtodelegatetheworkofpaintingtothreeprotected
methods: paintComponent() , paintBorder() , and paintChildren() .
allocated to the border.
ize the UI delegate's paint() method should just override paintComponent() .
If you're not concerned about UI delegates, borders, and children, the previous
SwingCanvas class should meet your needs. For more information, check out The
Java Tutorial's “Performing Custom Painting” lesson ( ht-
index.html ) .
Java 2D
Java 2D is a collection of AWT extensions that provide advanced two-dimensional
graphical, textual, and imaging capabilities. This API offers a flexible framework for
Search WWH ::

Custom Search