java swing怎么控制按钮的位置啊?
importjavax.swing.*;importjava.awt.*;publicclasstestextendsJFrame{publictest(){setSiz...
import javax.swing.*;
import java.awt.*;
public class test extends JFrame{
public test(){
setSize(350,200);
setLocation(500,200);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLayout(new BorderLayout());
setTitle("用户信息");
String str[] = {"属性","信息"};
Object str2[][]={{"姓名",""},{"职工号",""},{"身份证号",""},{"性别",""},{"出生年月",""}};
JTable table = new JTable(str2,str);
JButton Button1 = new JButton("修改信息");
JButton Button2 = new JButton("修改密码");
JLabel Label = new JLabel("用户:",JLabel.CENTER);
JScrollPane scrollpane = new JScrollPane(table);
Box box = Box.createHorizontalBox();
box.add(Button1);
box.add(Button2);
add(table,BorderLayout.NORTH);
add(Label,BorderLayout.CENTER);
add(box,BorderLayout.SOUTH);
}
public static void main(String []args){
test Test = new test();
Test.setVisible(true);
}
}
两个按钮怎么放到中间啊,求教 展开
import java.awt.*;
public class test extends JFrame{
public test(){
setSize(350,200);
setLocation(500,200);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLayout(new BorderLayout());
setTitle("用户信息");
String str[] = {"属性","信息"};
Object str2[][]={{"姓名",""},{"职工号",""},{"身份证号",""},{"性别",""},{"出生年月",""}};
JTable table = new JTable(str2,str);
JButton Button1 = new JButton("修改信息");
JButton Button2 = new JButton("修改密码");
JLabel Label = new JLabel("用户:",JLabel.CENTER);
JScrollPane scrollpane = new JScrollPane(table);
Box box = Box.createHorizontalBox();
box.add(Button1);
box.add(Button2);
add(table,BorderLayout.NORTH);
add(Label,BorderLayout.CENTER);
add(box,BorderLayout.SOUTH);
}
public static void main(String []args){
test Test = new test();
Test.setVisible(true);
}
}
两个按钮怎么放到中间啊,求教 展开
展开全部
你可以将容器的整体布局设置为FlowLayout,然后在FlowLayout中添加一个Box布局,Box再添加3个部分,分别是表格、标签和按钮,两个按钮可以在用一个再新建一个Box对象并添加进去,下面是代码:
import javax.swing.*;
import java.awt.*;
public class test extends JFrame{
public test()
{
setSize(300,200);
setLocationRelativeTo(null); //使窗体居中显示
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLayout(new FlowLayout());
setTitle("用户信息");
String str[] = {"属性","信息"};
Object str2[][]={{"姓名",""},{"职工号",""},{"身份证号",""},{"性别",""},{"出生年月",""}};
JTable table = new JTable(str2,str);
JButton Button1 = new JButton("修改信息");
JButton Button2 = new JButton("修改密码");
JLabel Label = new JLabel("用户:",JLabel.CENTER);
JScrollPane scrollpane = new JScrollPane(table);
Box box = Box.createVerticalBox();
Box buttonBox = Box.createHorizontalBox();
buttonBox.add(Button1);
buttonBox.add(Button2);
box.add(table);
box.add(Label);
box.add(buttonBox);
add(box);
}
public static void main(String []args)
{
test Test = new test();
Test.setVisible(true);
}
}
import javax.swing.*;
import java.awt.*;
public class test extends JFrame{
public test()
{
setSize(300,200);
setLocationRelativeTo(null); //使窗体居中显示
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLayout(new FlowLayout());
setTitle("用户信息");
String str[] = {"属性","信息"};
Object str2[][]={{"姓名",""},{"职工号",""},{"身份证号",""},{"性别",""},{"出生年月",""}};
JTable table = new JTable(str2,str);
JButton Button1 = new JButton("修改信息");
JButton Button2 = new JButton("修改密码");
JLabel Label = new JLabel("用户:",JLabel.CENTER);
JScrollPane scrollpane = new JScrollPane(table);
Box box = Box.createVerticalBox();
Box buttonBox = Box.createHorizontalBox();
buttonBox.add(Button1);
buttonBox.add(Button2);
box.add(table);
box.add(Label);
box.add(buttonBox);
add(box);
}
public static void main(String []args)
{
test Test = new test();
Test.setVisible(true);
}
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询