作者在 2014-05-14 12:54:00 发布以下内容
import javax.swing.*;
import java.awt.*;
public class demo_7
{
public static void main(String[] args)
{
demo_7_1 test=new demo_7_1();
}
}
class demo_7_1 extends JFrame
{
GridBagLayout gridbaglayout=new GridBagLayout();
GridBagConstraints gridbagconstraints;
JPanel jp;
JButton jbutton1;
JButton jbutton2;
JButton jbutton3;
JButton jbutton4;
JButton jbutton5;
public demo_7_1()
{
this.setVisible(true);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setBounds(0,0,400,300);
jp=new JPanel();
this.setContentPane(jp);
gridbagconstraints=new GridBagConstraints();
gridbagconstraints.gridx=GridBagConstraints.REMAINDER;
gridbagconstraints.gridy=0;
// gridbagconstraints.gridwidth=4;//表示该组件为该行中的最后一行
// gridbagconstraints.gridheight=2;
jp.setLayout(gridbaglayout);
jbutton1=new JButton("jbutton1");
jbutton2=new JButton("jbutton2");
jbutton3=new JButton("jbutton3");
jbutton4=new JButton("jbutton4");
jbutton5=new JButton("jbutton5");
jp.add(jbutton1);
jp.add(jbutton2);
jp.add(jbutton3);
jp.add(jbutton4);
jp.add(jbutton5);
gridbaglayout.setConstraints(jbutton1,gridbagconstraints);
}
}
import java.awt.*;
public class demo_7
{
public static void main(String[] args)
{
demo_7_1 test=new demo_7_1();
}
}
class demo_7_1 extends JFrame
{
GridBagLayout gridbaglayout=new GridBagLayout();
GridBagConstraints gridbagconstraints;
JPanel jp;
JButton jbutton1;
JButton jbutton2;
JButton jbutton3;
JButton jbutton4;
JButton jbutton5;
public demo_7_1()
{
this.setVisible(true);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setBounds(0,0,400,300);
jp=new JPanel();
this.setContentPane(jp);
gridbagconstraints=new GridBagConstraints();
gridbagconstraints.gridx=GridBagConstraints.REMAINDER;
gridbagconstraints.gridy=0;
// gridbagconstraints.gridwidth=4;//表示该组件为该行中的最后一行
// gridbagconstraints.gridheight=2;
jp.setLayout(gridbaglayout);
jbutton1=new JButton("jbutton1");
jbutton2=new JButton("jbutton2");
jbutton3=new JButton("jbutton3");
jbutton4=new JButton("jbutton4");
jbutton5=new JButton("jbutton5");
jp.add(jbutton1);
jp.add(jbutton2);
jp.add(jbutton3);
jp.add(jbutton4);
jp.add(jbutton5);
gridbaglayout.setConstraints(jbutton1,gridbagconstraints);
}
}