我有這個小程序顯示在apanel ..圖像,但我無法滾動添加到它..這是我的代碼添加JScrollPane的在面板上顯示的圖像
的類擴展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);
}
那麼我在這裏做了什麼錯誤?
謝謝..以及我也會在圖像 – CiCi 2009-11-06 20:31:12
上做scalnig和ather事情,但即使是縮放也可以通過覆蓋JLabel上的「paint」方法來處理 – aperkins 2009-11-06 21:23:27