gpt4 book ai didi

java - SwingUtilities.invokeAndWait 未运行

转载 作者:行者123 更新时间:2023-11-29 06:17:12 25 4
gpt4 key购买 nike

run() 方法中的代码未被执行。谁能告诉我为什么?

startButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
if(creator == null) {
String[] args = getArguments();
try {
writeSettingsFile(args);
} catch(IOException io) {}

consolePanel.addLine("Starting...");
bar.setIndeterminate(true);
try {
SwingUtilities.invokeAndWait(new Runnable() {

public void run() {
MessageConsole console = new MessageConsole(getConsole().getTextPane(), self, null);
console.redirectOut(new Color(240, 240, 240), null);
console.redirectErr(Color.RED, null);
console.setMessageLines(consolePanel.getHeight() / 17);
try {
SomeApp.main(getArguments());
} catch (Exception ex) {
Logger.getLogger(OSXWorldPanel.class.getName()).log(Level.SEVERE, null, ex);
}
}
});
} catch (InterruptedException ex) {
Logger.getLogger(OSXWorldPanel.class.getName()).log(Level.SEVERE, null, ex);
} catch (InvocationTargetException ex) {
Logger.getLogger(OSXWorldPanel.class.getName()).log(Level.SEVERE, null, ex);
}

}
}
});

抛出错误:

Exception in thread "AWT-EventQueue-0" java.lang.Error: Cannot call invokeAndWait from the event dispatcher thread
at java.awt.EventQueue.invokeAndWait(EventQueue.java:1017)
at javax.swing.SwingUtilities.invokeAndWait(SwingUtilities.java:1320)

最佳答案

如果您在 EDT 中,则不必调用 invokeAndWait。在您的示例中,您似乎处于美国东部时间。

关于java - SwingUtilities.invokeAndWait 未运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4630043/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com