JAVA 关于setBounds()
我已经将JFrame以及其容器的Layout设置成了null,为什么这时候调用控件的setBounds()还是没用效果?publicclasstmextendsJFram...
我已经将JFrame以及其容器的Layout设置成了null,为什么这时候调用控件的setBounds()还是没用效果?
public class tm extends JFrame
{
private int x = 400;
private int y = 300;
private Font font;
public tm()
{
setLayout(null);
//设置窗口标题和大小
setTitle("登录");
setSize(x, y);
//设置容器为MyJPanel
setContentPane(new MyJPanel());
//居中显示
Toolkit toolkit = Toolkit.getDefaultToolkit();
Dimension dimension = toolkit.getScreenSize();
int sx = dimension.width;
int sy = dimension.height;
setLocation((sx>>1)-(x>>1), (sy>>1)-(y>>1));
//不可变化大小
setResizable(false);
//输入账号
JTextField account_input = new JTextField();
add(account_input);
account_input.setBounds(120, 30, 250, 40);
account_input.setOpaque(false);
JTextField password_input = new JTextField();
add(password_input);
password_input.setBounds(120, 90, 250, 40);
password_input.setOpaque(false);
//设置字体
font = new Font("黑体", Font.PLAIN, 30);
account_input.setFont(font);
password_input.setFont(font);
setDefaultCloseOperation(EXIT_ON_CLOSE);
setVisible(true);
}
public static void main(String[] args)
{
setDefaultLookAndFeelDecorated(true);
new tm();
}
} 展开
public class tm extends JFrame
{
private int x = 400;
private int y = 300;
private Font font;
public tm()
{
setLayout(null);
//设置窗口标题和大小
setTitle("登录");
setSize(x, y);
//设置容器为MyJPanel
setContentPane(new MyJPanel());
//居中显示
Toolkit toolkit = Toolkit.getDefaultToolkit();
Dimension dimension = toolkit.getScreenSize();
int sx = dimension.width;
int sy = dimension.height;
setLocation((sx>>1)-(x>>1), (sy>>1)-(y>>1));
//不可变化大小
setResizable(false);
//输入账号
JTextField account_input = new JTextField();
add(account_input);
account_input.setBounds(120, 30, 250, 40);
account_input.setOpaque(false);
JTextField password_input = new JTextField();
add(password_input);
password_input.setBounds(120, 90, 250, 40);
password_input.setOpaque(false);
//设置字体
font = new Font("黑体", Font.PLAIN, 30);
account_input.setFont(font);
password_input.setFont(font);
setDefaultCloseOperation(EXIT_ON_CLOSE);
setVisible(true);
}
public static void main(String[] args)
{
setDefaultLookAndFeelDecorated(true);
new tm();
}
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询