- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我是 Swing 的新手,正在 Eclipse 中制作一个非常基本的事件处理程序。这是我写的代码:
public class SwingDemo2 {
JLabel jl;
public SwingDemo2() {
JFrame jfr = new JFrame("Swing Event Handling");
jfr.setSize(250, 100);
jfr.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
jl = new JLabel();
jl.setVisible(false);
JButton jb1 = new JButton("OK");
jb1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
jl.setText("You Pressed OK");
jl.setVisible(true);
}
});
JButton jb2 = new JButton("Reset");
jb2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
jl.setText("You Pressed Reset");
jl.setVisible(true);
}
});
jfr.setLayout(new BorderLayout());
jfr.add(jl, SwingConstants.NORTH);
jfr.add(jb1, SwingConstants.EAST);
jfr.add(jb2, SwingConstants.WEST);
jfr.setVisible(true);
}
public static void main(String[] args) {
// TODO Auto-generated method stub
SwingUtilities.invokeLater(new Runnable() {
public void run() {
new SwingDemo2();
}
});
}
}
Eclipse 提示我打开调试透视图,他向我显示了错误:线程 [AWT-EventQueue-0](暂停(异常 IllegalArgumentException))
EventDispatchThread.run() 行:不可用 [局部变量不可用]
当我使用 FlowLayout
而不是 BorderLayout
时,我没有收到任何错误。
我一直试图在门户网站上查找有关错误的信息,我遇到了 this类似的问题。答案是在不解释问题的情况下更改一堆设置(这也没有帮助)。请解释错误,以便我确保不再重复。提前致谢!
注意:更新了错误信息
最佳答案
使用 BorderLayout
代替 SwingConstant
,jfr.add(jl, BorderLayout.NORTH);
SwingConstants
是为 TextLayout
实现的,而不是为 JComponents 布局
关于java - EventDispatchThread.run() 行 : not available error in eclipse,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14183951/
所以我试图显示一个图像(ball),我最终将通过用户输入来控制它。要知道,图像只是使用线程的 sleep 方法每隔一段时间显示一次。 我创建了 2 个类,一个扩展了 JPanel,另一个扩展了 JFr
我们在运行应用程序结束时收到此错误。我在谷歌搜索但不知道是什么原因导致这个错误以及这意味着什么。该怎么办以及如何解决? 我什至不知道是什么引发了这个异常...... Exception breakpo
这是我不明白的设计决定。 Android 和 JME 都遵循启动应用程序的线程是 UI 线程的策略,您要注意将资源消耗的东西卸载到另一个线程。 另一方面,在 Swing 中,您将 EventQueue
我使用 JEditorPane 作为“橡皮图章”将 HTML 文本呈现为 PDF。我需要文本以特定宽度换行,并且需要在文本后面应用白色“突出显示”。因此,我在 PDF 渲染线程中创建一个 JEdito
我是 Swing 的新手,正在 Eclipse 中制作一个非常基本的事件处理程序。这是我写的代码: public class SwingDemo2 { JLabel jl; public SwingD
当我尝试在调试器中启动我的代码时出现以下错误。 EventDispatchThread.run() line: not available [local variables unavailable]
不久前,我们向应用程序添加了一些代码来检测并尝试从 Swing EDT 死锁中恢复,因此用户至少可以保存他们的文件(最好不要出现死锁,但是......) 。在 Java 1.6 中,这很容易。检测 E
当 dumpStackTrace 的第一个元素位于 java.awt.EventDispatchThread.run 时,为什么 isEventDispatchThread() 返回 false?
这是我在使用 Eclipse 进行调试时遇到的一个小烦恼。选中“未捕获的异常时暂停执行”后,调试器通常会在引发异常的位置暂停线程。然而,事件调度线程上的异常会导致它在 EventDispatchThr
我是一名优秀的程序员,十分优秀!