一個非常簡單的問題。我嘗試運行一個非常簡單的演示,從Eclipse創建並顯示一個Window Frame,但沒有任何反應。沒有錯誤,沒有窗口,代碼運行完成。從Eclipse運行時未出現Java JFrame窗口
我添加了斷點並確保代碼按預期運行。該代碼是直接從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();
}
});
}
}
我的設置(開普勒SR2):
- eclipse.buildId = 4.3.2.M20140221-1700
- java.version = 1.8.0_05
- java.vendor = Oracle公司
- BootLoader的常量:OS = MacOSX的,ARCH = x86_64的,WS =可可, 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? – 2014-09-20 16:39:46
您是否嘗試過使用不同的IDE或從終端運行它? – 2014-09-20 16:42:07
@Vince - 將它導出到jar中,然後從終端運行它,彈出窗口。 – user4061565 2014-09-20 17:00:14