【发布时间】:2014-11-15 01:23:25
【问题描述】:
一个非常简单的问题。我尝试运行一个非常简单的演示来从 Eclipse 创建和显示一个窗口框架,但没有任何反应。没有错误,没有窗口,代码运行完成。
我添加了断点并确保代码按预期运行。代码直接来自 Java 教程 (FrameDemo),我只是重命名了包以适合我放置它的位置(此包中的其他代码运行良好):
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):
- eclipse.buildId=4.3.2.M20140221-1700
- java.version=1.8.0_05
- java.vendor=甲骨文公司
- 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 cocoa -arch x86_64 -product org.eclipse.epp.package.java.product -keyring /Users/steve/.eclipse_keyring -showlocation
我还检查了配置 -> 错误日志;仍然没有,没有错误。我尝试了其他类似的演示,结果相同。
任何帮助将不胜感激,因为我已经坚持了一天多。
【问题讨论】:
-
它应该显示,因为我看不出代码有什么问题。您是否尝试过从头开始重新加载 Eclipse?
-
您是否尝试过使用不同的 IDE 或从终端运行它?
-
@Vince - 将其导出到 jar 中,然后从终端运行它,弹出窗口。
-
不,不重启,重新安装。从头开始。
-
@user4061565:不,我不建议你这样做,因为这个网站主要是为了回答这些问题。相反,请尝试为您自己的问题写一个清晰的答案,然后发布,然后在时间限制允许后接受。这是我们在这里想要和需要的东西(我认为),因为您这样做可能会帮助未来的用户,这就是它的全部意义。
标签: java eclipse macos swing jfreechart