日期:2014-05-20  浏览次数:20622 次

布局设计的GridLayout
import javax.swing.*;
import java.awt.*; 
public class TestGridLayout{
public static void main(String args[]){
        JFrame win=new JFrame("窗体"); 
        win.setBounds(200,200,600,600);
        win.setVisible(true);
        JButton bSouth=new JButton("南"),
               bNorth=new JButton("北"),
               bEast =new JButton("东"),
               bWest =new JButton("西");
        JPanel bCenter=new JPanel();
        
        win.add(bNorth,BorderLayout.NORTH);
        win.add(bSouth,BorderLayout.SOUTH);
        win.add(bEast,BorderLayout.EAST);
        win.add(bWest,BorderLayout.WEST); 
        win.add( bCenter,BorderLayout.CENTER);
        
        JButton b[];      
        bCenter.setLayout(new Gridlayout(3,3,5,5));//一直在这报错java.awt.Gridlayout cannot be resolved to a type

        b=new JButton[9];
        for(int i=0;i<b.length;i++){
         b[i]=new JButton(""+i);
          bCenter.add(b[i]);
        }
      
        win.validate();
        win.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }
}
求高手解决,,,,,
------最佳解决方案--------------------
引用:
new Gridlayout(3,3,5,5));
你这里3  3  5  5指的是什么?
改成
GridLayout(3, 5);试试


这不知道就查一下 API不就懂了么
------其他解决方案--------------------
“  bCenter.setLayout(new Gridlayout(3,3,5,5));//一直在这报错”
你那一句中的 GridLayout 中的Layout 是写的layout 把l 改成大写的就好了.  
------其他解决方案--------------------
Gridlayout -> GridLayout
------其他解决方案--------------------
new Gridlayout(3,3,5,5));
你这里3  3  5  5指的是什么?
改成
GridLayout(3, 5);试试 

------其他解决方案--------------------
引用:
new Gridlayout(3,3,5,5));
你这里3  3  5  5指的是什么?
改成
GridLayout(3, 5);试试

明白了,几乎没用过四个参数的。搜了一下才知道
GridLayout(int rows, int cols, int hgap, int vgap)  rows行 cols 列, 列间距hgap, 行间距vgap
------其他解决方案--------------------