2016-05-06 18 views
0

Ich verwende Swing JFrame als Mainframe für meine Anwendung. Ich habe eine Schaltfläche, die ein neues Fenster erstellen soll. Aber es wird direkt in der Initialisierung abstürzen und ich habe keine Ahnung warum. HierExceptionInInitializerError beim Erstellen neuer Stufe

public class Dialog { 
    private Stage window; 

public void display() { 
    window = new Stage(); //This is line 45. This is place where it crash 
    window.setMinWidth(350); 
    window.setMinHeight(500); 
    window.initModality(Modality.APPLICATION_MODAL); 
    window.setTitle("Add new Stuff"); 
//more code here 
} 
} 

ist ganz Ausnahmefehler

Exception in thread "AWT-EventQueue-0" java.lang.ExceptionInInitializerError 
    at javafx.stage.Window.<init>(Window.java:1179) 
    at javafx.stage.Stage.<init>(Stage.java:236) 
    at javafx.stage.Stage.<init>(Stage.java:224) 
    at main.Dialog.display(Dialog.java:45) 
    at main.MainFrame.jButtonAddZamActionPerformed(MainFrame.java:400) 
    at main.MainFrame.access$400(MainFrame.java:12) 
    at main.MainFrame$5.actionPerformed(MainFrame.java:227) 
    at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2022) 
    at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2346) 
    at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402) 
    at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259) 
    at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:252) 
    at java.awt.Component.processMouseEvent(Component.java:6525) 
    at javax.swing.JComponent.processMouseEvent(JComponent.java:3324) 
    at java.awt.Component.processEvent(Component.java:6290) 
    at java.awt.Container.processEvent(Container.java:2234) 
    at java.awt.Component.dispatchEventImpl(Component.java:4881) 
    at java.awt.Container.dispatchEventImpl(Container.java:2292) 
    at java.awt.Component.dispatchEvent(Component.java:4703) 
    at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4898) 
    at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4533) 
    at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4462) 
    at java.awt.Container.dispatchEventImpl(Container.java:2278) 
    at java.awt.Window.dispatchEventImpl(Window.java:2750) 
    at java.awt.Component.dispatchEvent(Component.java:4703) 
    at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:751) 
    at java.awt.EventQueue.access$500(EventQueue.java:97) 
    at java.awt.EventQueue$3.run(EventQueue.java:702) 
    at java.awt.EventQueue$3.run(EventQueue.java:696) 
    at java.security.AccessController.doPrivileged(Native Method) 
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:75) 
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:86) 
    at java.awt.EventQueue$4.run(EventQueue.java:724) 
    at java.awt.EventQueue$4.run(EventQueue.java:722) 
    at java.security.AccessController.doPrivileged(Native Method) 
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:75) 
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:721) 
    at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201) 
    at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116) 
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105) 
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101) 
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93) 
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:82) 
Caused by: java.lang.IllegalStateException: This operation is permitted on the event thread only; currentThread = AWT-EventQueue-0 
    at com.sun.glass.ui.Application.checkEventThread(Application.java:443) 
    at com.sun.glass.ui.Screen.setEventHandler(Screen.java:245) 
    at com.sun.javafx.tk.quantum.QuantumToolkit.setScreenConfigurationListener(QuantumToolkit.java:674) 
    at javafx.stage.Screen.<clinit>(Screen.java:80) 
    ... 43 more 

Irgendwelche Ideen, warum es abstürzt? Danke

+1

* "Diese Operation wird auf dem Event Thread nur erlaubt" * ... versucht, das Google? – Tom

+0

Ich kenne nur einen Weg, wie man ein Dialogfenster erstellt. Über Bühne. Ich habe nie eine andere Methode benutzt und ich habe keine Ahnung, wie ich das machen soll. Ich weiß auch nicht, was "Event-Thread" bedeutet. – Shocky

+0

Warum sollten Sie Swing mit Java-FX mischen? Außer aus gutem Grund, mach es so oder so. –

Antwort

1

Sie können JavaFx-Komponente in einer Swing-Anwendung haben. Wir haben das für eine ERP-Anwendung getan, um das Dashboard mit JavaFx-Charts anzuzeigen.

enter image description here

Initialisierung JavaFx bezogenen Code sollte wie unten erfolgen.

 Platform.runLater(new Runnable() { 
      @Override 
      public void run() { 
       initFX(fxPanel); 
      } 
     }); 

Bitte unten Link verweist für weitere Details https://docs.oracle.com/javase/8/javafx/interoperability-tutorial/swing-fx-interoperability.htm

+0

Der Link, den Sie zur Verfügung gestellt haben, ist großartig! Ich habe versucht, es in FX zu machen, aber ich hatte schreckliche Probleme mit TableView, aber das löste mein Problem ziemlich schnell. Vielen Dank! – Shocky

Verwandte Themen