我用了FlowLayout布局,也用了JScrollPane,然后我想显示4副不同的图片,每行显示2个, 
然后,我就用了FOR语句,但是却并不是我所希望的!换了GridLayout后,还是不行啊~ 
请教 

解决方案 »

  1.   


    setLayout(new GridLayout(3,2));//3行两列
             add(new Button("1"));
             add(new Button("2"));
             add(new Button("3"));
             add(new Button("4"));
             add(new Button("5"));
             add(new Button("6"));
    这是加按钮的,你换成图片就可以了
      

  2.   

    Java codeimport java.awt.*;
    import javax.swing.*;
    public class Jcsdn extends JFrame
    {
    public Jcsdn()
    {
    this.setLayout(new GridLayout(2,2,5,5));
    Container c=getContentPane();

    JPanel jp= new JPanel(new GridLayout(2,2,5,5));

    Icon icon1 =new ImageIcon("src/IMG_0531.jpg");
    JLabel jl=new JLabel(icon1);
    Icon icon2 =new ImageIcon("src/IMG_0535.jpg");
    JLabel j2=new JLabel(icon2);
    Icon icon3= new ImageIcon("src/IMG_0536.jpg");
    JLabel j3=new JLabel(icon3);

    JLabel j4= new JLabel(new ImageIcon("src/IMG_0539.jpg"));
    jp.add(jl);
    jp.add(j2);
    jp.add(j3);
    jp.add(j4);
    JScrollPane js=new JScrollPane(jp);
    js.setBounds(10, 10, 500, 1000);
    this.getContentPane().add( js);
    this.setSize(1000,1000);


    this.setVisible(true);

    }

    public static void main(String a[])
    {
    new Jcsdn();
    }
    我写了个,可以显示4幅图片的,采用了布局管理器,也用了JScrollPane,看能给LZ些参考不??
      

  3.   

    new FlowLayout(行数,列数,行间距,列间距);
      

  4.   

    new GridLayout(行数,列数,行间距,列间距);