Reputation: 327
When I select "run" in Netbeans, my GUI does not display. 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)
}
Upvotes: 0
Views: 38574
Reputation: 1
If you work in NetBeans, after building, check that you are running the file you need from the project. To do this, press shift + F6
Upvotes: 0
Reputation: 91
Follow path YourProject/packacge which your java file is in then, You can right click to your project then click from over there "run file".This worked for me.
Upvotes: 0
Reputation: 208944
JPanel
forms are not created with main
methods, in GUI Builder, which you do need.
JPanel
is not a top-level container, which you do need to run a Swing app.
A top-level container is, for instance, a JFrame
. So you should have created a JFrame
form instead of a JPanel
form. When you do this in Netbeans GUI Builder, a main
method will be provided for you.
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.
You may also need to set/change the Main class to the new JFrame
form you just created. You can that by looking at this answer
Upvotes: 2
Reputation: 1260
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:
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.
Morover, remember to setVisible
every JPanel that you implement and also the top-level container.
Useful links:
Upvotes: 1