1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
|
public class MonPanel extends JComponent {<div style="margin-left:40px">
private Image image;
public void paintComponent(Graphics g) {
if (image != null) {
g.drawImage(image,0,0,null);
}
}
public void paintView(JScrollPane sp) {
this.image = getImage(sp.getViewport().getView());
repaint();
}</div><div style="margin-left:40px">public Image getImage(Component component){
if(component==null){return null;}
int width = component.getWidth();
int height = component.getHeight();
BufferedImage image = new BufferedImage(width, height,
BufferedImage.TYPE_INT_RGB);
Graphics2D g = image.createGraphics();
component.paintAll(g);
g.dispose();
return image;
}</div>} |
Partager