Java Swing JWindow应用程序崩溃 [英] Java Swing JWindow application crash

查看:279
本文介绍了Java Swing JWindow应用程序崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我使用JDK1.8_40或更新版本(Oracle或OpenJDK执行相同操作),以下代码和对话框调整大小将使应用程序崩溃(尝试过Windows 7,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;

公共类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);
定时器t =新定时器(300,新ActionListener(){
@Override
public void actionPerformed(ActionEvent e){
dependentWindow .setVisible(!dependentWindow.isVisible());
}
});
t.start();
}
});
}

私有静态JWindow getjWindow(JDialog对话框){
JWindow w = new JWindow(对话框);
JPanel panel = new JPanel();
panel.add(新JButton(按钮));
w.add(小组);
返回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(未知来源)
sun.awt.windows.WComponentPeer.setBounds(未知来源)
sun.awt.windows.WWindowPeer.setBounds(未知来源)
java.awt。 Component.reshapeNativePeer(Unknown Source)
java.awt.Component.reshape(Unknown Source)
java.awt.Window.reshape(Unknown Source)
java.awt.Component.setBounds(Unknown)来源)
java.awt.Window.setBounds(未知来源)
java.awt.Component.resize(未知来源)
java.awt.Component.setSize(未知来源)
java.awt.Window.setSize(未知来源)

Windows问题详情(显示2个错误):

 问题签名:
问题事件名称:BEX64
应用程序名称:java.exe
应用程序版本:8.0.60.13
应用程序时间戳:55404a69
故障模块名称:StackHash_08b3
故障模块版本:0.0.0.0
故障模块时间戳:00000000
异常偏移:0000000300000002
异常代码:c0000005
例外数据:0000000000000008
操作系统版本:6.1.7601.2.1.0.256.48
地区信息ID:1033
附加信息1:08b3
附加信息2:08b36dcca93c38acb7c92ef4a729e798
附加信息3:5d68
附加信息4:5d682eddcc7a5d6b5452fc95535d5ac9

第二个:



<$问题签名:
问题事件名称:APPCRASH
应用程序名称:java.exe
应用程序版本:8.0.60.13
应用程序时间戳:55404a69
Fault Modu le名称:StackHash_d693
故障模块版本:0.0.0.0
故障模块时间戳:00000000
异常代码:c000041d
异常偏移:0000000300000002
操作系统版本:6.1.7601.2 .1.0.256.48
地区ID:1033
附加信息1:d693
附加信息2:d6933f192f50114566e03a88a59a6417
附加信息3:9096
附加信息4:9096dfe271c183defc2620e74bdaec28


解决方案

你的Timer没有在Swing UI上调度Swing UI事件线。你需要invokeLater你的runnable所以它在正确的线程上运行。



或者,你可以让计时器执行一个SwingWorker,并使用done()方法发布事件(保证在事件发送线程上)


If I use JDK1.8_40 or newer (Oracle or OpenJDK do the same), the following code together with a dialog resize will crash the application (tried Windows 7, x64, 64bit 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;
}
}

I haven't found other complaints about this and haven't posted a bug on oracle's website yet. A possible workaround is changing the JWindow to an undecorated JDialog but that comes with other issues for me so I wouldn't change this yet.

Did anyone else hit this problem and found a workaround?

Added the stack:

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 problem details (shows 2 errors):

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

second one:

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

解决方案

Your Timer is not dispatching the Swing UI events on the Swing UI Thread. You need to "invokeLater" your runnable so it gets ran on the right thread.

Alternatively, you could have the timer execute a SwingWorker, with the done() method posting the event (it is guaranteed to be on the event dispatch thread)

这篇关于Java Swing JWindow应用程序崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆