为什么 Eclipse 插件代码无法从外部 java swing 应用程序调用 swingworking 线程?
我已经实现了一个独立的java应用程序,它使用GUI的swing框架。作为GUI的一部分,有一个JTextArea,它在单击按钮后出现,并且在后台处理作业后在jtextarea中附加一些文本。我正在使用 SwingWorker 库,因为我不希望我的 jtextarea 冻结应用程序并且它工作得很好。所以作业代码位于重写的 doInBackground 内。
我面临的问题是,当我作为 Eclipse 插件的一部分启动这个 GUI 应用程序时。我已经用我的 swing 应用程序构建了一个 jar,并且向 Eclipse 工作台添加了一个扩展。一开始,应用程序正常启动,但是当应用程序流程转到调用 swingworker 时,这个特定的 jtextarea 冻结并且没有任何反应。似乎我的 Swingworker 的 doInBackground() 函数内的代码没有被调用。 我在 eclipse pugin 代码中启动应用程序,如下所示:
SwingUtilities.invokeLater(new Runnable() {public void run() {
new MainFrame.setVisible(true);
}
});
其中 MAinFrame 是 java 程序的 JFrame 类。 你知道为什么会发生这种情况吗?
I have implemented a standalone java application which uses the swing framework for GUI.As part of the GUI there is a JTextArea which appears after a button is clicked on and some text is appended at the jtextarea after a job is being processed in the background.I am using the SwingWorker library, as i dont't want my jtextarea to freeze the app and it works perfectly.So the job code lies inside the overriden doInBackground.
The problem that i am facing is when i launch this GUI application as part of an Eclipse plugin.I have build a jar with my swing app and i've added an extension to the Eclipse workbench.In the beginning the app launched properly but when the application flow goes to the point when the swingworker is to be invoked, this specific jtextarea is freezing and nothing happened.It seems that the code inside the doInBackground() function of my Swingworker is not invoked.
I am launching the app inside the eclipse pugin code as below:
SwingUtilities.invokeLater(new Runnable() {public void run() {
new MainFrame.setVisible(true);
}
});
where MAinFrame is a JFrame class of the java program.
Do you know why is this happening?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在同一个进程中混合 SWT 和 AWT/Swing UI 并不容易。它们需要不同的事件循环。您的代码冻结是因为 Awt/Swing 事件循环未在 Eclipse 进程中运行。您可以使用 SWT 重写 UI 或研究 SWT-AWT 桥接器。这座桥“可以工作”,但存在许多故障。它实际上只适用于 AWT/Swing 数量巨大且需要临时解决方案而将 UI 移植到 SWT 的情况。
It is not easy to mix SWT and AWT/Swing UI in the same process. They require different event loops. Your code is freezing because Awt/Swing event loop is not running in the Eclipse process. You can either re-write your UI in SWT or research SWT-AWT bridge. The bridge "works", but has numerous glitches. It is really only appropriate for situation where there is an enormous amount of AWT/Swing and a temporary solution is necessary while the UI is ported to SWT.
您是否尝试过使用 Runtime.exec() 调用外部程序?
您可能知道,混合 Eclipse SWT/Jface 和 Swing 是一个困难的话题。
Have you tried invoking your external program with Runtime.exec()?
As you might be aware, mixing Eclipse SWT/Jface and Swing is a difficult topic.