【问题标题】:How to call a class that was created using windowBuilder (Eclipse)如何调用使用 windowBuilder (Eclipse) 创建的类
【发布时间】:2017-06-06 11:55:55
【问题描述】:

我习惯于通过运行来创建另一个类的实例

Config con = new Config();
con.setVisible(true);

但是,这似乎不适用于 WindowBuilder 插件在 Config 中设置 gui 的方式。运行上一个命令时,它会创建一个空的、微小的 JFrame。 Config 的 main 方法只包含以下内容:

public static void main(String[] args) {
    EventQueue.invokeLater(new Runnable() {
        public void run() {
            try {
                Config window = new Config();
                window.frame.setVisible(true);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    });
}

构造函数只是调用包含内容创建的初始化方法:

public Config(){
initialize();
}
private void initialize() {
        frame = new JFrame();
        frame.setBounds(100, 100, 450, 300);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.getContentPane().setLayout(null);
        frame.setLocationRelativeTo(null);
        frame.setResizable(false);

//other configuration here
}

如何从另一个类调用 Config 以运行并显示?

【问题讨论】:

    标签: java eclipse class windowbuilder


    【解决方案1】:

    回答

    创建该类的新对象后。

    WindowShow ws = new WindowsShow();
    ws.frame.setVisible(true);
    

    它会变得完美

    【讨论】:

    【解决方案2】:

    好的,找到答案了。首先,要停止显示微小的无用框架,请不要从初始类中设置 visible true 。而是运行:

    Config con = new Config();
    

    然后,在Config的构造函数中,初始化一切后,添加

    frame.setVisible(true);
    

    【讨论】:

      猜你喜欢
      • 2016-03-29
      • 2012-05-18
      • 1970-01-01
      • 2013-04-04
      • 2015-08-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多