My problem is that I did a Java program in NetBeans and it works normally, but the problem is that when I open the .jar outside the IDE, the window is not opened.
Here is a simple code with the same problem:
package bbb;
import javax.swing.*;
public class NewFrame extends JFrame{
public NewFrame() {
initComponents();
}
private void initComponents() {
jButton1 = new JButton();
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
setResizable(false);
setSize(new java.awt.Dimension(700, 400));
jButton1.setText("btn");
GroupLayout layout = new GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(305, 305, 305)
.addComponent(jButton1)
.addContainerGap(319, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(GroupLayout.Alignment.LEADING)
.addGroup(GroupLayout.Alignment.TRAILING,layout.createSequentialGroup()
.addContainerGap(228, Short.MAX_VALUE)
.addComponent(jButton1)
.addGap(217, 217, 217))
);
ImageIcon icon = new ImageIcon(getClass().getResource("/bbb/btn.png"));
jButton1.setIcon(icon);
pack();
}
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(() -> {
new NewFrame().setVisible(true);
});
}
private JButton jButton1;
}
Some details:
- The NewFrame class is already the primary one;
- I have already put a folder with the same package name, in the same directory, with the same images;
- If I leave the button with no icon, .jar opens normally;
- The program normally opens in NetBeans (with or without an icon);
- Also tried to open cmd (unsuccessfully);
- The .jar does not open the window (JFrame), but it appears open in the background in the Task Manager.
Please help me. I do not know what else to do ;-; .