0

我有一个来自 Swing 的问题,我有两个表单,第一个表单用于 MDI,第二个表单用于登录,我希望当用户输入正确的密码和用户名时,用户可以登录到 MDI 的表单。MDI表单使用 jform 和登录表单使用jinternalframe,我定义JDesktopPane并添加登录,但我想在jframe(MDI表单)中使用按钮,当我添加按钮时JDesktopPane,它可以添加但我无法设置按钮的位置。请帮助我如何设置我的jinternalframe和按钮的位置?

这是我的代码:

     Login frame = new Login();
    frame.setVisible(true); 
    desktop=new JDesktopPane();
    desktop.add(frame,BorderLayout.CENTER);
    setContentPane(desktop);
    frame.setSelected(true);  
    frame.setLocation(500, 200);

    FlowLayout flo = new FlowLayout();
    desktop.setLayout(flo);
    JButton buttonSaveCustumer = new JButton("Create Customer");
    buttonSaveCustumer.setLocation(70, 80);
    this.add(buttonSaveCustumer);

此致

4

1 回答 1

0

见下面的方法,//在使用下面的方法之前不要忘记将layout属性设置为null

public void setBounds(int x, int y, int width, int height)

移动此组件并调整其大小。左上角的新位置由 x 和 y 指定,新大小由 width 和 height 指定。此方法更改与布局相关的信息,因此使组件层次结构无效。

Parameters:
x - the new x-coordinate of this component
y - the new y-coordinate of this component
width - the new width of this component
height - the new height of this component
于 2014-03-25T17:05:16.180 回答