java GridBagLayout布局,下面的代码怎么修改让一个按钮占两行一列,
importjava.awt.*;importjava.util.*;importjava.applet.Applet;importjavax.swing.JFrame;...
import java.awt.*;
import java.util.*;
import java.applet.Applet;
import javax.swing.JFrame;
public class GridBagEx2 extends Applet {
protected void makebutton1(String name,GridBagLayout gridbag, GridBagConstraints c) {
Button button = new Button(name);
gridbag.setConstraints(button, c);
add(button);
}
public void init() {
GridBagLayout gridbag = new GridBagLayout();
GridBagConstraints c = new GridBagConstraints();
setLayout(gridbag);
c.fill = GridBagConstraints.BOTH;
c.gridwidth = 1;
c.gridheight = 1;
makebutton1("Button6", gridbag, c);
c.gridwidth = 1;//reset to the default 重置为默认
c.gridheight = 2;
c.gridwidth = GridBagConstraints.REMAINDER;
c.weighty = 1.0;
makebutton1("Button5", gridbag, c); //another row 另一排
c.gridwidth = GridBagConstraints.REMAINDER;
c.gridwidth = 1;
c.gridheight = 1;
makebutton1("Button7", gridbag, c);
}
public static void main(String args[]) {
JFrame f = new JFrame("GridBag Layout Example");
GridBagEx2 ex1 = new GridBagEx2();
ex1.init();
f.add("Center", ex1);
f.pack();
f. setVisible(true);
}
}
怎么让按钮5占两行 展开
import java.util.*;
import java.applet.Applet;
import javax.swing.JFrame;
public class GridBagEx2 extends Applet {
protected void makebutton1(String name,GridBagLayout gridbag, GridBagConstraints c) {
Button button = new Button(name);
gridbag.setConstraints(button, c);
add(button);
}
public void init() {
GridBagLayout gridbag = new GridBagLayout();
GridBagConstraints c = new GridBagConstraints();
setLayout(gridbag);
c.fill = GridBagConstraints.BOTH;
c.gridwidth = 1;
c.gridheight = 1;
makebutton1("Button6", gridbag, c);
c.gridwidth = 1;//reset to the default 重置为默认
c.gridheight = 2;
c.gridwidth = GridBagConstraints.REMAINDER;
c.weighty = 1.0;
makebutton1("Button5", gridbag, c); //another row 另一排
c.gridwidth = GridBagConstraints.REMAINDER;
c.gridwidth = 1;
c.gridheight = 1;
makebutton1("Button7", gridbag, c);
}
public static void main(String args[]) {
JFrame f = new JFrame("GridBag Layout Example");
GridBagEx2 ex1 = new GridBagEx2();
ex1.init();
f.add("Center", ex1);
f.pack();
f. setVisible(true);
}
}
怎么让按钮5占两行 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询