3

パネルに画像を表示するためのこの小さなプログラムがありますが、スクロールを追加できません。これが私のコードです

画像を表示するためにjpanelを拡張するクラス:

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;

}

表示パネルを保持するためのimageContainerと呼ばれる別のパネルを持つメインフレームのサンプル:

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);


}

だから私がここでした間違いは何ですか?

4

2 に答える 2

1

「imagecontainer」はスクロール可能なパネルに追加されるクラスであるため、スクロール可能にするために特定のサイズを超える必要があるパネルです。「showPanel」は、スクロール可能なコンテナに直接配置する必要があります。

于 2009-11-06T19:44:05.433 に答える