从Eclipse运行时未出现Java JFrame窗口 [英] Java JFrame Window not appearing when run from Eclipse

查看:548
本文介绍了从Eclipse运行时未出现Java JFrame窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一个非常简单的问题.我尝试运行一个非常简单的演示,以从Eclipse创建并显示一个窗口框架,但没有任何反应.没有错误,没有窗口,代码运行完毕.

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.

我添加了断点,并确保代码按预期运行.该代码直接来自Java教程(FrameDemo),我只是将包重命名为适合我放置的位置(此包中的其他代码运行良好):

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();
            }
        });
    }
}

我的设置(Kepler SR2):

My setup (Kepler SR2):

  • eclipse.buildId = 4.3.2.M20140221-1700
  • java.version = 1.8.0_05
  • java.vendor = Oracle Corporation
  • BootLoader常数:OS = macosx,ARCH = x86_64,WS = cocoa,NL = en_US
  • 框架参数:-product org.eclipse.epp.package.java.product -keyring/Users/steve/.eclipse_keyring -showlocation
  • 命令行参数:-os macosx -ws可可-arch x86_64 -product org.eclipse.epp.package.java.product -keyring/Users/steve/.eclipse_keyring -showlocation

我还检查了Configuration->错误日志;还是一无所有,没有错误.我尝试了其他类似的演示,结果相同.

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.

推荐答案

事实证明我遇到了图书馆问题.我已经从jfreechart导入了.lib目录中的所有jar.实际上,只需要两个,而一些不必要的则标记为swt和实验性的.一旦我删除了所有不需要的东西,进行了清洁,然后重新构建,一切工作就很好了.

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.

奇怪的是,将jfreechart库(包括有冲突的jar)的顺序更改为底部无济于事,必须删除多余的jar.

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.

不是jfreechart问题,显然是我自己的库导入问题.如果遇到这种情况,建议您尝试删除一些可能冲突的库,然后清理,构建并再次运行.

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.

这篇关于从Eclipse运行时未出现Java JFrame窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆