javajframe移动无任务栏窗口_从Eclipse运行时未显示Java JFrame窗口

本文介绍了一位开发者在使用Eclipse开发Java应用程序时遇到的问题:运行简单的窗口展示示例代码后窗口未能正常显示。通过排查,最终发现是由于不必要的第三方库引入导致的问题,并给出了移除冗余库后的解决方案。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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.

解决方案

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.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值