13

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):

  • eclipse.buildId=4.3.2.M20140221-1700
  • java.version=1.8.0_05
  • java.vendor=Oracle Corporation
  • BootLoader constants: OS=macosx, ARCH=x86_64, WS=cocoa, NL=en_US
  • Framework arguments: -product org.eclipse.epp.package.java.product -keyring /Users/steve/.eclipse_keyring -showlocation
  • Command-line arguments: -os macosx -ws cocoa -arch x86_64 -product org.eclipse.epp.package.java.product -keyring /Users/steve/.eclipse_keyring -showlocation

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.

Hovercraft Full Of Eels
  • 283,665
  • 25
  • 256
  • 373
user4061565
  • 545
  • 1
  • 5
  • 16
  • It should display as I see nothing wrong with the code. Have you tried re-loading Eclipse from scratch? – Hovercraft Full Of Eels Sep 20 '14 at 16:39
  • Have you tried running it using a different IDE or from the terminal? – Vince Sep 20 '14 at 16:42
  • @Vince - exporting it to a jar, and then running it from the terminal works, the window pops up. – user4061565 Sep 20 '14 at 17:00
  • @Hovercraft - I tried restarting Eclipse, Same thing: nothing shows up. – user4061565 Sep 20 '14 at 17:00
  • 1
    No, not restarting, re-installing. From scratch. – Hovercraft Full Of Eels Sep 20 '14 at 17:00
  • Is new process created when you run your application from Eclipse? (new javaw.exe should be created in task manager for new frame, if you are using windows) – Mykola Evpak Sep 20 '14 at 17:04
  • @Hovercraft - ok. I re-installed Kepler from scratch, and if I pointed it to my old workspace, same thing; if I pointed it to a new workspace folder and cleared up library issues, it worked!! It turns out that when importing a library (jfreechart), I imported a bunch of other unnecessary jars (the name still started with jfreechart, but with swt or experimental added). Removing these extra jars from the library in the original workspace cleared up the problem, and now everything works!!! How do I close this question now? (newbe here) – user4061565 Sep 20 '14 at 17:47
  • 1
    @user4061565: no, I wouldn't advise you do that as this site is mainly about answering such questions. Instead, try to write a clean answer **to your own question**, post it, and then accept it later after the time limit allows. This is the type of stuff we want and need here (I think) because your doing this will likely help future users, and that's what it's all about. – Hovercraft Full Of Eels Sep 20 '14 at 17:58
  • And touché on solving this, and thanks for getting back to us with the resolution. Again be sure that you post your solution as an answer, not as an edit to your question, because that is what it is. You may wish to add the part about using JFreeChart in the question as well. I'm going to add a JFreeChart tag. – Hovercraft Full Of Eels Sep 20 '14 at 18:00

2 Answers2

10

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.

user4061565
  • 545
  • 1
  • 5
  • 16
  • Interesting! I got the SAME issue. Never thought how importing more jars than needed could possibly have caused this. Anyway, nice catch! – One Two Three Jul 08 '16 at 17:14
  • very true. i had similar issue. My app was not starting , nothing was happening when i use to run. Removed jfreechart-1.0.19-swt.jar from reference lib and all worked smooth !!! – Rahul Sawant Sep 06 '16 at 17:45
  • OMG - I just ran into the same problem and thought I was going nuts. Removed the "external jar dep" on SWT and boom - theswing window showed up... – slott Nov 11 '19 at 15:57
3

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.