📄 gridbaglayoutpanel.java
字号:
package layouttest;import java.awt.*;import javax.swing.*;public class GridBagLayoutPanel extends JPanel { GridBagLayout gridBagLayout1 = new GridBagLayout(); JButton jButton1 = new JButton(); JButton jButton2 = new JButton(); JButton jButton3 = new JButton(); JButton jButton4 = new JButton(); JButton jButton5 = new JButton(); JButton jButton6 = new JButton(); public GridBagLayoutPanel() { try { jbInit(); } catch(Exception ex) { ex.printStackTrace(); } } void jbInit() throws Exception { jButton1.setText("1"); this.setLayout(gridBagLayout1); jButton2.setText("2"); jButton3.setText("3"); jButton4.setText("4"); jButton5.setText("5"); jButton6.setText("6"); this.add(jButton1, new GridBagConstraints(0, 0, 1, 1, 10.0, 0.0 ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); this.add(jButton2, new GridBagConstraints(1, 0, 1, 1, 20.0, 0.0 ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); this.add(jButton3, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0 ,GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); this.add(jButton4, new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0 ,GridBagConstraints.SOUTHEAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); this.add(jButton5, new GridBagConstraints(1, 2, 1, 1, 0.0, 0.0 ,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 32)); this.add(jButton6, new GridBagConstraints(2, 0, 1, 3, 0.0, 0.0 ,GridBagConstraints.SOUTHWEST, GridBagConstraints.NONE, new Insets(20, 10, 20, 10), 0, 88)); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -