2017-07-07 62 views
0

我正在使用swing,我无法更改WindowBuilder中COMPONENTS区域中的JFrame。 我只能看到主框架。 当我按下一个按钮时,我创建了一个新的Frame,但是我不能用WindowBuilder编辑它。在WindowBuilder中更改JFrame Eclipse

enter image description here

 frameMain.setVisible(false); 
     frameLogin = new JFrame("Login Admin"); 
     frameLogin.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 
     frameLogin.setSize(600, 400); 
     frameLogin.setLocationRelativeTo(null); 
     frameLogin.setVisible(true); 

我想在的WindowBuilder EDIT frameLogin,任何解决方案? 通过在WindowBuilder中创建一个新的JFrame,它会在其他文件中创建另一个类。 enter image description here

+1

您的'frameLogin'属于'JFrame'类型,您不能编辑标准库。使用WindowBuilder创建一个新的'JFrame'并在你的代码中使用它。 – kalsowerus

+0

@kalsowerus看我编辑帖子。无论如何,它创造了我在另一个文件框架。我想要它在同一个文件中,是可能的吗? –

+1

你需要这个的任何好理由?同一个文件中的多个类很少是一个好主意。 – kalsowerus

回答

0

我这样做: 在我看来(frameMain)我声明这一点:

private loginFrameAdmin frameLoginA; 
private loginFrameUser frameLoginU; 

其中loginFrameAdmin是一个JFrame这样的:

import javax.swing.JFrame; 

public class loginFrameAdmin { 

    private JFrame frameLogin; 
    public loginFrameAdmin() { 
     frameLogin = new JFrame("Login Amministratore"); 
     frameLogin.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 
     frameLogin.setSize(600, 400); 
     frameLogin.setLocationRelativeTo(null); 
     frameLogin.setVisible(true); 
    } 
} 

然后在同样的观点(frameMain )我添加了一个类:

public void adminPage() { 
     JOptionPane.showMessageDialog(null, "Login for admins"); 
     frameMain.setVisible(false); 
     frameLoginA = new loginFrameAdmin(); 
    } 

现在我可以编辑我的JFrame,这要感谢@kalsowerus