I tried to execute the following code within Eclipse (OSX):
public static void main(String[] args) {
JFrame frame = new JFrame("Test");
frame.setSize(new Dimension(400, 30));
frame.add(new JButton("hello"));
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
The frame does not show up but I get the following console messages:
2014-05-16 14:45:35.230 java[8685:903] [Java CocoaComponent compatibility mode]: Enabled
2014-05-16 14:45:35.232 java[8685:903] [Java CocoaComponent compatibility mode]: Setting timeout for SWT to 0.100000
2014-05-16 14:45:35.546 java[8685:903] *** __NSAutoreleaseNoPool(): Object 0x100612800 of class NSConcreteMapTableValueEnumerator autoreleased with no pool in place - just leaking
2014-05-16 14:45:35.547 java[8685:903] *** __NSAutoreleaseNoPool(): Object 0x100613f40 of class __NSCFDate autoreleased with no pool in place - just leaking
2014-05-16 14:45:35.547 java[8685:903] *** __NSAutoreleaseNoPool(): Object 0x100616e60 of class NSCFTimer autoreleased with no pool in place - just leaking
2014-05-16 14:45:35.550 java[8685:903] *** __NSAutoreleaseNoPool(): Object 0x10061d7c0 of class __NSCFDate autoreleased with no pool in place - just leaking
2014-05-16 14:45:35.550 java[8685:903] *** __NSAutoreleaseNoPool(): Object 0x10061e610 of class NSCFTimer autoreleased with no pool in place - just leaking
While, if I put the code into a java file outside of my Eclipse project and compile and run it via command line, everything is fine and the frame shows up. Can anybody help me troubleshooting?
UPDATE
the code now looks like this:
import javax.swing.*;
public class TestFrame {
public static void main(String[] args) {
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
createAndShowGUI();
}
private void createAndShowGUI() {
JFrame frame = new JFrame("Test");
System.out.println(SwingUtilities.isEventDispatchThread());
frame.getContentPane().add(new JButton("hello"));
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.pack();
frame.setVisible(true);
}
});
}
}
This does not solve the problem (as already mentioned by user DSquare). I figured out that it seems to be a problem with that specific Eclipse project. If I create a new Eclipse project (same Eclipse), the code runs without an error message and the frame shows up. I still don't have a clue which project cnfigurations may cause it. I don't have swt.jar in my classpath (though org.eclipse.swt and org.eclipse.swt.cocoa.macosx.x86_64 in my plugin-dependencies).