I have this little program to display images on apanel .. but I can’t add scroll to it .. and this is my code
a class that extends jpanel to display an image:
public class ShowPanel extends JPanel{
public ShowPanel(BufferedImage image, int height, int width) {
this.image = image;
this.height = height;
this.width = width;
}
public void paintComponent(Graphics g) {
super.paintComponent(g);
g.drawImage(image, height, width, null);
}
public void setImage(BufferedImage image, int height, int width) {
this.image = image;
this.height = height;
this.width = width;
}
private BufferedImage image;
private int height;
private int width;
}
and a sample main frame with another panel called imageContainer to hold the display panel:
public class MainFrame extends javax.swing.JFrame {
public MainFrame() {
initComponents();
image = null;
path = "PantherOnLadder.gif";
image = Actions.loadImage(path);
showPanel = new ShowPanel(image, 0, 0);
spY = toolBar.getY() + toolBar.getHeight();
showPanel.setBounds(0, spY, image.getWidth(), image.getHeight());
showPanel.repaint();
imageContainer.add(showPanel);
JScrollPane scroller = new JScrollPane(imageContainer);
scroller.setAutoscrolls(true);
}
so i made a mistake here?
source
share