A very simple problem. I try to run a very simple demo to created and display a Window Frame from Eclipse, and nothing happens. No errors, no window, the code runs to completion.
I added breakpoints and made sure the code runs as expected. The code is straight from Java tutorials (FrameDemo), I just renamed the package to fit where I placed it (other code from this package runs fine):
package ui;
import java.awt.*;
import javax.swing.*;
/* FrameDemo.java requires no other files. */
public class FrameDemo {
/**
* Create the GUI and show it. For thread safety,
* this method should be invoked from the
* event-dispatching thread.
*/
private static void createAndShowGUI() {
//Create and set up the window.
JFrame frame = new JFrame("FrameDemo");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JLabel emptyLabel = new JLabel("");
emptyLabel.setPreferredSize(new Dimension(175, 100));
frame.getContentPane().add(emptyLabel, BorderLayout.CENTER);
//Display the window.
frame.pack();
frame.setVisible(true);
}
public static void main(String[] args) {
//Schedule a job for the event-dispatching thread:
//creating and showing this application's GUI.
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
createAndShowGUI();
}
});
}
}
My setup (Kepler SR2):
I also checked Configuration -> error logs; still nothing, no errors. I tried other similar demos, same results.
Any help would be appreciated as I have been stuck on this for over a day.
Select Window > Preferences from the menu to open it and then expand the node "JFormDesigner" in the tree. See Preferences for details. You can also set project specific settings in the Eclipse project dialog. Select Project > Properties from the menu to open it and then expand the node "JFormDesigner" in the tree.
Run As > Java Application wont show up if the class that you want to run does not contain the main method. Make sure that the class you trying to run has main defined in it. It did have. It is just that it didn't show the run as app.
To make the frame visible, invoke setVisible(true) on it. Set or get the operation that occurs when the user pushes the close button on this frame.
macOS + Eclipse + swt.jar gives this issue.
Turns out, in macOS, Eclipse adds a special argument -XstartOnFirstThread
when starting the GUI app if you have swt.jar in the classpath. After removing swt.jar from external libraries (used to build classpath), problem solved.
It turns out I had a library problem. I had had imported all the jars in the .lib directory from jfreechart. In reality only two were needed and some unnecessary ones were labeled swt and experimental. Once I removed all the ones that were not needed, did a clean, and rebuilt, everything worked fine.
Oddly, changing the order of the jfreechart library (which included the conflicting jars) to the bottom did not help, the extra jars had to be removed.
Not a jfreechart issue, obviously my own library import issue. If you run into this I suggest you try to remove some of the libraries that may be conflicting, then clean, build, and run again.
Thanks to Hovercraft Full Of Eels and everyone else who responded for helping me out.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With