2017-07-07 41 views

回答

0

你能更具體地說明你在問什麼嗎? 我成功運行下面的代碼。

@FXML 
private void handleButtonAction(ActionEvent event) { 
    SwingUtilities.invokeLater(new Runnable() { 

     @Override 
     public void run() { 
      // TODO Auto-generated method stub 
      JFrame frame = new JFrame("FrameDemo"); 

      // 2. Optional: What happens when the frame closes? 
      frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 

      // 3. Create components and put them in the frame. 
      // ...create emptyLabel... 
      frame.getContentPane().add(new JLabel("Test"), BorderLayout.CENTER); 

      // 4. Size the frame. 
      frame.pack(); 

      // 5. Show it. 
      frame.setVisible(true); 
     } 
    }); 
} 

handleButtonAction是在控制類我JavaFX項目的功能。

您是否想創建一個單獨的窗口,或者將Swing嵌入到JavaFX窗口中?

+0

@James_D我已經更新了將代碼添加到AWT事件分派線程的答案。這是否充分解決了您的擔憂? – gabe870

+0

這將工作。 –