⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gridlayoutdemo.java

📁 本java源程序包括了大量的学习程序(共27章)方便大家学习
💻 JAVA
字号:
import java.awt.*;
import javax.swing.*;
public class GridLayoutDemo extends JFrame 
{
   public GridLayoutDemo() 
   {
      super("GridLayout");
      setSize(450,300);    
      try
      {  //系统外观
		UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
	  }catch(Exception e){}
		
      //获取内容面板并且设置布局管理器
      Container container = getContentPane(); //获得内容面板
      container.setBackground(Color.YELLOW);
      
      //设置为网格布局管理器,为五行五列,水平及垂直间距均为10个像素
      container.setLayout(new GridLayout(5, 5, 10, 10));
      
      for(int i = 1; i <= 5; i++)
    	  for(int j = 1; j <= 5; j++)
    	  {
    	  	//项内容面板的网格中添加按钮组件
    		  container.add(new JButton( "Button" + ((i-1)*5+j) ) );
    	  }
      
      setVisible(true);
      setDefaultCloseOperation(EXIT_ON_CLOSE);
   }
   
   public static void main(String arguments[]) 
   {
      GridLayoutDemo application = new GridLayoutDemo();
   }
}    

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -