Java Swing JWindow 应用程序崩溃
Java Swing JWindow application crash
如果我使用 JDK1.8_40 或更新版本(Oracle 或 OpenJDK 做同样的事情),下面的代码连同对话框调整大小将使应用程序崩溃(试过Windows7、x64、64 位JDK)
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JPanel;
import javax.swing.JWindow;
import javax.swing.SwingUtilities;
import javax.swing.Timer;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class Main {
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
final JDialog dialog = new JDialog();
dialog.add(new JPanel());
dialog.setVisible(true);
dialog.setBounds(100, 100, 100, 100);
final JWindow dependentWindow = getjWindow(dialog);
dependentWindow.setVisible(true);
dependentWindow.setBounds(100, 100, 100, 100);
Timer t = new Timer(300, new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
dependentWindow.setVisible(!dependentWindow.isVisible());
}
});
t.start();
}
});
}
private static JWindow getjWindow(JDialog dialog) {
JWindow w = new JWindow(dialog);
JPanel panel = new JPanel();
panel.add(new JButton("button"));
w.add(panel);
return w;
}
}
我还没有发现关于此的其他投诉,也没有在 oracle 的网站上发布错误。一种可能的解决方法是将 JWindow 更改为未修饰的 JDialog,但这对我来说还有其他问题,所以我暂时不会更改它。
有没有其他人遇到这个问题并找到解决方法?
添加了堆栈:
WARN 2015-05-04 15:21:21,707 - AWT-EventQueue-0, Id = 17, Priority = 6: RUNNABLE
sun.awt.windows.WWindowPeer.reshapeFrame(Native Method)
sun.awt.windows.WDialogPeer.reshape(Unknown Source)
sun.awt.windows.WComponentPeer.setBounds(Unknown Source)
sun.awt.windows.WWindowPeer.setBounds(Unknown Source)
java.awt.Component.reshapeNativePeer(Unknown Source)
java.awt.Component.reshape(Unknown Source)
java.awt.Window.reshape(Unknown Source)
java.awt.Component.setBounds(Unknown Source)
java.awt.Window.setBounds(Unknown Source)
java.awt.Component.resize(Unknown Source)
java.awt.Component.setSize(Unknown Source)
java.awt.Window.setSize(Unknown Source)
Windows 问题详情(显示 2 个错误):
Problem signature:
Problem Event Name: BEX64
Application Name: java.exe
Application Version: 8.0.60.13
Application Timestamp: 55404a69
Fault Module Name: StackHash_08b3
Fault Module Version: 0.0.0.0
Fault Module Timestamp: 00000000
Exception Offset: 0000000300000002
Exception Code: c0000005
Exception Data: 0000000000000008
OS Version: 6.1.7601.2.1.0.256.48
Locale ID: 1033
Additional Information 1: 08b3
Additional Information 2: 08b36dcca93c38acb7c92ef4a729e798
Additional Information 3: 5d68
Additional Information 4: 5d682eddcc7a5d6b5452fc95535d5ac9
第二个:
Problem signature:
Problem Event Name: APPCRASH
Application Name: java.exe
Application Version: 8.0.60.13
Application Timestamp: 55404a69
Fault Module Name: StackHash_d693
Fault Module Version: 0.0.0.0
Fault Module Timestamp: 00000000
Exception Code: c000041d
Exception Offset: 0000000300000002
OS Version: 6.1.7601.2.1.0.256.48
Locale ID: 1033
Additional Information 1: d693
Additional Information 2: d6933f192f50114566e03a88a59a6417
Additional Information 3: 9096
Additional Information 4: 9096dfe271c183defc2620e74bdaec28
您的计时器没有在 Swing UI 线程上调度 Swing UI 事件。您需要 "invokeLater" 您的可运行对象,以便它在正确的线程上获得 运行。
或者,您可以让定时器执行一个 SwingWorker,使用 done() 方法发布事件(保证 运行teed 在事件调度线程上)
这个答案有点晚了,but the issue has been fixed。
如果我使用 JDK1.8_40 或更新版本(Oracle 或 OpenJDK 做同样的事情),下面的代码连同对话框调整大小将使应用程序崩溃(试过Windows7、x64、64 位JDK)
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JPanel;
import javax.swing.JWindow;
import javax.swing.SwingUtilities;
import javax.swing.Timer;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class Main {
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
final JDialog dialog = new JDialog();
dialog.add(new JPanel());
dialog.setVisible(true);
dialog.setBounds(100, 100, 100, 100);
final JWindow dependentWindow = getjWindow(dialog);
dependentWindow.setVisible(true);
dependentWindow.setBounds(100, 100, 100, 100);
Timer t = new Timer(300, new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
dependentWindow.setVisible(!dependentWindow.isVisible());
}
});
t.start();
}
});
}
private static JWindow getjWindow(JDialog dialog) {
JWindow w = new JWindow(dialog);
JPanel panel = new JPanel();
panel.add(new JButton("button"));
w.add(panel);
return w;
}
}
我还没有发现关于此的其他投诉,也没有在 oracle 的网站上发布错误。一种可能的解决方法是将 JWindow 更改为未修饰的 JDialog,但这对我来说还有其他问题,所以我暂时不会更改它。
有没有其他人遇到这个问题并找到解决方法?
添加了堆栈:
WARN 2015-05-04 15:21:21,707 - AWT-EventQueue-0, Id = 17, Priority = 6: RUNNABLE
sun.awt.windows.WWindowPeer.reshapeFrame(Native Method)
sun.awt.windows.WDialogPeer.reshape(Unknown Source)
sun.awt.windows.WComponentPeer.setBounds(Unknown Source)
sun.awt.windows.WWindowPeer.setBounds(Unknown Source)
java.awt.Component.reshapeNativePeer(Unknown Source)
java.awt.Component.reshape(Unknown Source)
java.awt.Window.reshape(Unknown Source)
java.awt.Component.setBounds(Unknown Source)
java.awt.Window.setBounds(Unknown Source)
java.awt.Component.resize(Unknown Source)
java.awt.Component.setSize(Unknown Source)
java.awt.Window.setSize(Unknown Source)
Windows 问题详情(显示 2 个错误):
Problem signature:
Problem Event Name: BEX64
Application Name: java.exe
Application Version: 8.0.60.13
Application Timestamp: 55404a69
Fault Module Name: StackHash_08b3
Fault Module Version: 0.0.0.0
Fault Module Timestamp: 00000000
Exception Offset: 0000000300000002
Exception Code: c0000005
Exception Data: 0000000000000008
OS Version: 6.1.7601.2.1.0.256.48
Locale ID: 1033
Additional Information 1: 08b3
Additional Information 2: 08b36dcca93c38acb7c92ef4a729e798
Additional Information 3: 5d68
Additional Information 4: 5d682eddcc7a5d6b5452fc95535d5ac9
第二个:
Problem signature:
Problem Event Name: APPCRASH
Application Name: java.exe
Application Version: 8.0.60.13
Application Timestamp: 55404a69
Fault Module Name: StackHash_d693
Fault Module Version: 0.0.0.0
Fault Module Timestamp: 00000000
Exception Code: c000041d
Exception Offset: 0000000300000002
OS Version: 6.1.7601.2.1.0.256.48
Locale ID: 1033
Additional Information 1: d693
Additional Information 2: d6933f192f50114566e03a88a59a6417
Additional Information 3: 9096
Additional Information 4: 9096dfe271c183defc2620e74bdaec28
您的计时器没有在 Swing UI 线程上调度 Swing UI 事件。您需要 "invokeLater" 您的可运行对象,以便它在正确的线程上获得 运行。
或者,您可以让定时器执行一个 SwingWorker,使用 done() 方法发布事件(保证 运行teed 在事件调度线程上)
这个答案有点晚了,but the issue has been fixed。