我要在GUI上面显示图片,由于图片太大了,我只能显示一部分,希望在上下架滚动条,可以上下滚动察看全部图片,那位高手能告诉我怎么做吗。

解决方案 »

  1.   

    把图片放到JPanel中,把JPanel放到JScrollPane中。
      

  2.   

    你好,我直接把图片加载到JPanel里,图像好像会按大小自动缩放扑满JPanel;你是怎么实现图片原样大小加载到JPanel里。。
    JScrollPane PicScrollPane=new JScrollPane(PicturePanel);
    container.add(PicPanel, borderLayout.CENTER);
      

  3.   

    container.add(PicScrollPane, null);应该是这样吧
      

  4.   

    import javax.swing.*;public class Test extends JFrame {
        private JPanel pane = null;
        private JScrollPane span = null;    public Test() {
            super("Test");        pane = new JPanel();
            span = new JScrollPane(pane);        pane.add(new JLabel(new ImageIcon("d:/xxx.jpg")));
            //span = new JScrollPane(new JLabel(new ImageIcon("d:/xxx.jpg"))); //或者直接把JLabel加到JScrollPane中也成
            this.getContentPane().add(span);
            this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            this.setSize(300, 200);
            this.setLocationRelativeTo(null);
            this.setVisible(true);
        }    public static void main(String args[]) {
            Test t = new Test();
        }}