java - 在另一个类中创建我的 Gui 的对象时,框架加载但内部没有任何内容

标签 java eclipse user-interface windowbuilder

我已公开初始化方法,但没有帮助,我已将此处和外部类的可见设置为 true,如下所示,我们将不胜感激。我使用 Eclipse 中的窗口生成器工具创建了图形用户界面

GeneralWindow frame = new GeneralWindow();
                        frame.setVisible(true);

打包图形用户界面;

import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.JTextField;
import javax.swing.UIManager;
import javax.swing.UIManager.LookAndFeelInfo;
import javax.swing.JLabel;
import javax.swing.JTextArea;
import java.awt.Font;

public class GeneralWindow extends JFrame{

    private JFrame frame;
    private JTextField textField;

    /**
     * Launch the application.
     */
    public static void main(String[] args) {

        try {
            for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (Exception e) {
            // If Nimbus is not available, you can set the GUI to another look and feel.
        }

        EventQueue.invokeLater(new Runnable() {
            public void run() {
                try {
                    GeneralWindow window = new GeneralWindow();
                    window.frame.setVisible(true);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });
    }

    /**
     * Create the application.
     */
    public GeneralWindow() {
        initialize();
    }

    /**
     * Initialize the contents of the frame.
     */
    private void initialize() {
        frame = new JFrame();
        frame.setBounds(100, 100, 450, 300);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.getContentPane().setLayout(null);

        JButton btnNewButton = new JButton("Order");
        btnNewButton.setBounds(309, 12, 115, 23);
        frame.getContentPane().add(btnNewButton);

        JButton btnNewButton_1 = new JButton("Search");
        btnNewButton_1.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
            }
        });
        btnNewButton_1.setBounds(309, 46, 115, 23);
        frame.getContentPane().add(btnNewButton_1);

        JButton btnNewButton_2 = new JButton("Stock");
        btnNewButton_2.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent arg0) {
            }
        });
        btnNewButton_2.setBounds(309, 80, 115, 23);
        frame.getContentPane().add(btnNewButton_2);

        JButton btnNewButton_3 = new JButton("Emplyoees");
        btnNewButton_3.setBounds(309, 114, 115, 23);
        frame.getContentPane().add(btnNewButton_3);

        JButton btnNewButton_4 = new JButton("Price Amend");
        btnNewButton_4.setBounds(309, 148, 115, 23);
        frame.getContentPane().add(btnNewButton_4);

        JButton btnNewButton_5 = new JButton("Total");
        btnNewButton_5.setBounds(309, 182, 115, 23);
        frame.getContentPane().add(btnNewButton_5);

        textField = new JTextField();
        textField.setBounds(10, 228, 178, 20);
        frame.getContentPane().add(textField);
        textField.setColumns(10);

        JLabel lblProductcodeBar = new JLabel("Productcode Bar");
        lblProductcodeBar.setFont(new Font("Tahoma", Font.BOLD, 11));
        lblProductcodeBar.setBounds(10, 209, 125, 14);
        frame.getContentPane().add(lblProductcodeBar);

        JButton btnEnter = new JButton("Enter");
        btnEnter.setBounds(198, 227, 89, 23);
        frame.getContentPane().add(btnEnter);

        JTextArea textArea = new JTextArea();
        textArea.setBounds(10, 11, 277, 196);
        frame.getContentPane().add(textArea);
    }


}

最佳答案

您正在使 GeneralWindow 类型的框架 frame 可见。但是您永远不会向该框架添加任何组件。相反,您的初始化方法会创建另一个框架,并向该框架添加许多组件。不要创建另一个框架,而是将组件添加到 this

关于java - 在另一个类中创建我的 Gui 的对象时,框架加载但内部没有任何内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42506847/

相关文章:

java - android中的抽屉导航不是全屏

java - 将图像名称更改为不同的图像名称(在服务器上部署后添加)在 eclipse ee 开发中不起作用

java - 为什么我无法清除 ArrayList 的两个子列表

java - 如何识别 Java 中的按键事件

java - 如果我已经完成向上转换,为什么要重写从子类调用的方法?

java - Servlet @WebServlet urlPatterns

java - Talend Open Studio 和 Eclipse - 将源代码从 eclipse 链接到 talend open studio 并将作业导出为测试

winapi - 开发具有一些图形编辑器功能的小型且快速的 GUI 应用程序的最佳组合是什么 - C++ 和(VB 或 Win32)?

java - 拥有多个带有滚动 Pane 的面板

java - Docker 镜像无法将我的 JSON 凭证 key 添加到我的 Google Cloud Natural Language 服务客户端