j'ai ce petit programme pour montrer des images sur apanel .. mais je ne suis pas en mesure d'ajouter un parchemin à lui .. et ceci est mon codeAjouter JScrollPane à un panneau qui montre une image
la classe étend JPanel pour afficher l'image:
public class ShowPanel extends JPanel{
public ShowPanel(BufferedImage image, int height, int width) {
this.image = image;
this.height = height;
this.width = width;
//this.setBounds(width, width, width, height);
}
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;
}
et un échantillon du cadre principal qui a un autre panneau appelé imageContainer pour maintenir le panneau montrant:
public class MainFrame extends javax.swing.JFrame {
/** Creates new form MainFrame */
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);
}
alors quelle est l'erreur que j'ai faite ici?
merci .. eh bien je vais aussi faire scalnig et ather des choses sur l'image – CiCi
mais même la mise à l'échelle peut être gérée juste en remplaçant la méthode "peinture" sur le JLabel – aperkins