58,454
社区成员
发帖
与我相关
我的任务
分享
public void init() {
Object rowData[][] = new Object[5][5];
String columnName[] = { "账号密码归属", "账号", "密码", "预留验证信息", "生成密码" };
button = new JButton("添加");
button.setBounds(150, 300, 60, 25);
add(button);
title = new JLabel("账号密码管理系统", JLabel.CENTER);
title.setFont(new Font("宋体", Font.BOLD, 25));
setLayout(new BorderLayout());
add(title, BorderLayout.NORTH);
table = new JTable(rowData, columnName);
JScrollPane scrollpane = new JScrollPane(table);
scrollpane.setBorder(new EmptyBorder(50, 0, 0, 0));
add(scrollpane, BorderLayout.CENTER);
JPanel panelSouth = new JPanel();
panelSouth.setLayout(new FlowLayout());
add(panelSouth, BorderLayout.SOUTH);
panelSouth.add(button);
};
public class MainFrame extends JFrame {
private JButton button;
private JLabel title;
private JTable table;
public MainFrame() {
super("账号密码管理系统");
init();
setSize(370, 370);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
// setResizable(false);
setVisible(true);
}
public void init() {
Object rowData[][] = new Object[5][5];
String columnName[] = { "账号密码归属", "账号", "密码", "预留验证信息", "生成密码" };
button = new JButton("添加");
button.setBounds(150, 300, 60, 25);
add(button);
title = new JLabel("账号密码管理系统", JLabel.CENTER);
title.setFont(new Font("宋体", Font.BOLD, 25));
title.setBounds(50, 5, 250, 25);
setLayout(null);
add(title);
table = new JTable(rowData, columnName);
JScrollPane scrollpane = new JScrollPane(table);
scrollpane.setBorder(new EmptyBorder(50, 0, 0, 0));
add(scrollpane);
scrollpane.setBounds(0, 30, 370, 250);
};
public static void main(String arg[]) {
MainFrame frame = new MainFrame();
}
}
一般使用swing做软件都会自己定制位置的,最大化的实现再另外写一套组件位置移位的代码。[/quote]
我用鼠标拖动改变窗口大小,button的位置还是一样不会跟着改变呀~~
public class MainFrame extends JFrame {
private JButton button;
private JLabel title;
private JTable table;
public MainFrame() {
super("账号密码管理系统");
init();
setSize(370, 370);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
// setResizable(false);
setVisible(true);
}
public void init() {
Object rowData[][] = new Object[5][5];
String columnName[] = { "账号密码归属", "账号", "密码", "预留验证信息", "生成密码" };
button = new JButton("添加");
button.setBounds(150, 300, 60, 25);
add(button);
title = new JLabel("账号密码管理系统", JLabel.CENTER);
title.setFont(new Font("宋体", Font.BOLD, 25));
title.setBounds(50, 5, 250, 25);
setLayout(null);
add(title);
table = new JTable(rowData, columnName);
JScrollPane scrollpane = new JScrollPane(table);
scrollpane.setBorder(new EmptyBorder(50, 0, 0, 0));
add(scrollpane);
scrollpane.setBounds(0, 30, 370, 250);
};
public static void main(String arg[]) {
MainFrame frame = new MainFrame();
}
}
一般使用swing做软件都会自己定制位置的,最大化的实现再另外写一套组件位置移位的代码。