I\'m a newbie to the paint/graphics and wonder how to add a JPanel to my code in such way that the entire graphics will be on a JPanel and not on the JFrame.
In other wo
Runnable
, establish an ActionListener
that calls repaint()
. Call it from a Swing Timer
.JComponent
or JPanel
BufferedImage
and add that to an ImageIcon
in a JLabel
.JComponent
if you do not need to add further children, or JPanel
if you do. For either, override paintComponent(Graphics)
instead of paint(Graphics)
.BufferedImage
might be a better choice for this use-case, since it seems to be animating a (supposedly intentionally persistant) series of lines.setBounds
! Instead, set a preferred size to the custom component, use sensible values for the constructor of the text area, and combine them with layouts (and appropriate padding and borders), then call pack()
on the frame after all components are added.repaint()
prior to the Thread
starting...What was the question? Oh right, if it can be inferred that the question is "How to combine other components with a custom painted component?" - use a nested layout. see the Nested Layout example.
If using a BufferedImage
as backing store, you might place it like the image in that example, except that you would leave out the JTable
above that, as well as the JSplitPane
.
Read the Swing tutorial on Custom Painting for the proper way to do this.