I have a JScrollPane and inside it I placed a JPanel.
There is also a button, when pressed, a rectangle of random length and width will be drawn
on the panel. So each time this button is pressed, the repaint method of the JPanel is called.
The problem is that sometimes the length of the rectangle is high and so the JPanel does not display it all, just part of it that already fits in the panel.
How can I make the JPanel display what is drawn inside it nomatter what the dimensions of the rectangle are?
One option is to draw the rectangle onto the
Graphicsobject of aBufferedImageof similar dimensions, and then use this image as theIconof aJLabel. Add this label to the panel at the arbitrary coordinates and thenrevalidatetheJScrollPaneand issue arepaintrequest.