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

📄 gridbagdemo.java

📁 Java学习源代码检索系统免费版
💻 JAVA
字号:
//==============================================================
// GridBagDemo.java - Demonstrates GridBagLayout class
//
// Java学习源代码检索系统 Ver 1.0 20031015 免费正式版
// 版权所有: 中国IT认证实验室(www.ChinaITLab.com)
// 程序制作: ChinaITLab网校教研中心
// 主页地址: www.ChinaITLab.com    中国IT认证实验室
// 论坛地址: bbs.chinaitlab.com  
// 电子邮件: Java@ChinaITLab.com
//==============================================================

import javax.swing.*;
import java.applet.*;
import java.awt.*;

public class GridBagDemo extends JApplet {

 protected void makeButton(String name, GridBagLayout gridbag, 
  GridBagConstraints c, JPanel pane)
 {
  JButton button = new JButton(name);
  gridbag.setConstraints(button, c);
  pane.add(button);
 }

 // Initialize applet and GUI buttons
 public void init() {
  JPanel pane = new JPanel();  // Create content pane
  // Create GridBagLayout and Constraints objects
  GridBagLayout gridbag = new GridBagLayout();
  GridBagConstraints c = new GridBagConstraints();
  pane.setLayout(gridbag);  // Tell pane to use gridbag layout

  // Create four "normal" buttons on the top row
  c.fill = GridBagConstraints.NONE;
  c.weightx = 1.0;
  makeButton("Button 1", gridbag, c, pane);
  makeButton("Button 2", gridbag, c, pane);
  makeButton("Button 3", gridbag, c, pane);
  c.gridwidth = GridBagConstraints.REMAINDER; 
  makeButton("Button 4", gridbag, c, pane);

  // Create a long button filling entire row
  c.fill = GridBagConstraints.BOTH;
  c.weightx = 0.0;
  makeButton("Button 5", gridbag, c, pane);

  // Create two buttons that fill the row
  c.gridwidth = GridBagConstraints.RELATIVE; 
  makeButton("Button 6", gridbag, c, pane);
  c.gridwidth = GridBagConstraints.REMAINDER;
  makeButton("Button 7", gridbag, c, pane);

  // Create a vertical button
  c.gridwidth = 1;
  c.gridheight = 2;
  c.weighty = 1.0;
  makeButton("Button 8", gridbag, c, pane);
  c.weighty = 0.0;

  // Create buttons to right of vertical Button 8
  c.gridwidth = GridBagConstraints.REMAINDER; 
  c.gridheight = 1;
  makeButton("Button 9", gridbag, c, pane);
  makeButton("Button 10", gridbag, c, pane);

  // Add content pane to applet top-level container
  getContentPane().add(pane, BorderLayout.CENTER);
  setSize(325, 250);
 }
}

⌨️ 快捷键说明

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