简体   繁体   English

当我在 NetBeans 中点击运行时,我的 GUI 不会显示

[英]My GUI will not display when I hit run in NetBeans

When I select "run" in Netbeans, my GUI does not display.当我 select 在 Netbeans 中“运行”时,我的 GUI 不显示。 It just displays a box on the bottom of the screen that says "Build successful".它只是在屏幕底部显示一个框,上面写着“构建成功”。

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package modelrange;

import javax.swing.DefaultBoundedRangeModel;

public class RangedModel extends javax.swing.JPanel {

    DefaultBoundedRangeModel myModel;

    public static void main(String[] args) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new RangedModel().setVisible(true);
            }
       });
    }

    /**
     * Creates new form RangedModel
     */
    public RangedModel() {
        myModel = new DefaultBoundedRangeModel(123, 100, 0, 1000);
        initComponents();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */

    private void initComponents() { 
    This is just the automated netbeans code from the GUI builder (edited out for the post)            
    }
  1. JPanel forms are not created with main methods, in GUI Builder, which you do need. JPanel形式与创建main方法,在GUI Builder中,你确实需要。

  2. JPanel is not a top-level container, which you do need to run a Swing app. JPanel不是顶层容器,你需要运行一个Swing应用程序。

  3. A top-level container is, for instance, a JFrame . 例如,顶级容器是JFrame So you should have created a JFrame form instead of a JPanel form. 所以你应该创建一个JFrame表单而不是JPanel表单。 When you do this in Netbeans GUI Builder, a main method will be provided for you. 在Netbeans GUI Builder中执行此操作时,将为您提供main方法。

  4. A simple fix would be just to create a new JFrame form, then just drag and drop the JPanel form to the JFrame form, as seen here , get rid of the main method in your JPanel form, then run the JFrame form class. 一个简单的修正将只是创建一个新JFrame窗体,然后只需拖放JPanel形式向JFrame形式,看到这里 ,摆脱了main在方法JPanel表单,然后运行JFrame窗体类。

  5. You may also need to set/change the Main class to the new JFrame form you just created. 您可能还需要将Main类设置/更改为刚刚创建的新JFrame表单。 You can that by looking at this answer 你可以通过查看这个答案

First of all, you are extending JPanel, it's wrong because as peeskillet wrote at points 2 and 3. Kind of top-level container are: 首先,你正在扩展JPanel,这是错误的,因为peeskillet在第2点和第3点写道。顶级容器的种类是:

  • JFrame : the window with the bar JFrame:带栏的窗口
  • JWindow : the window without bar JWindow:没有酒吧的窗户
  • JDialog : the window usually used to create option window JDialog:通常用于创建选项窗口的窗口

So you have to extend one of them, probably the first. 所以你必须扩展其中一个,可能是第一个。

Than in this top-level container you can create JPanel, one or more, everyone will be a container of another object which will be the contenent. 比在这个顶级容器中你可以创建一个或多个JPanel,每个人都将成为另一个对象的容器,这将是一个有争议的对象。

Morover, remember to setVisible every JPanel that you implement and also the top-level container. Morover,记得setVisible你实现的每个JPanel以及顶级容器。

Useful links: 有用的链接:

按照您的java文件所在的路径YourProject / packacge,您可以右键单击您的项目,然后点击那里的“运行文件”。这对我有用。

If you work in NetBeans, after building, check that you are running the file you need from the project.如果你在 NetBeans 工作,在构建之后,检查你是否正在运行项目中你需要的文件。 To do this, press shift + f6为此,请按 shift + f6

change JPanel to JFrame. 将JPanel更改为JFrame。 It will work. 它会工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 当我点击运行按钮时,我的 JFrame 不会出现,尽管 NetBeans 说它正在运行 - My JFrame won't show up when I hit Run button althought NetBeans said it is running 当我尝试在netbeans上运行GUI时,它说没有可用的类,我该怎么办? - When I try to run my GUI on netbeans it says that there are no available classes what can I do about that? 当我尝试运行NetBeans GUI应用程序时,它保持冻结状态 - NetBeans GUI Application keeps freezing when I try to run it 我对运行文件进行测试时,NetBeans GUI设计的行为不一致 - NetBeans GUI design acting inconsistent when I test with the run file 当我运行netbeans项目时,窗口中的内容不会打开,直到我达到最大化 - When i run a netbeans project the content in the window doesn't open until i hit maximize 当我点击自己的 API 时如何刷新 RecyclerView 显示 - How to Refresh RecyclerView display when I hit my own API Netbeans GUI不会显示 - Netbeans GUI wont display Netbeans GUI构建器-运行时的输出与编程显示中的输出不同 - Netbeans GUI builder - output different at run time than in programming display 为什么我的GUI不显示,而是通过NetBeans运行 - Why won't my GUI display, running via NetBeans 在主方法中创建GUI时似乎未显示GUI - GUI does not seem to display when I create it in my main method
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM