首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > J2SE开发 >

格局设计的GridLayout

2012-12-27 
布局设计的GridLayoutimport javax.swing.*import java.awt.* public class TestGridLayout{public stat

布局设计的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
------其他解决方案--------------------


不好意思分给错了

热点排行