2016-11-19 5 views
0

シーンのオブジェクトを作成しようとすると、そのコンポーネントにCSSスタイルが適用されますが、シーンのオブジェクトを作成する際に問題があるようです。 コンパイラは、rootをnullにすることはできません。 お願いします。javafxシーンオブジェクトのルートノードとは何ですか?

これは私のコードです:

輸入javafx.scene.Parent。 import javafx.scene.Scene;/* *

は、このライセンスのヘッダーを変更するプロジェクトのプロパティでライセンスヘッダを選択します。 *このテンプレートファイルを変更するには、[ツール|テンプレート *を開き、エディタでテンプレートを開きます。 * */

/** * @author アフマド */ パブリッククラスNewJFrameがjavax.swing.JFrameを{

private Parent root; 
private Parent Parent; 

/** 
* Creates new form NewJFrame 
*/ 
public NewJFrame() { 
    initComponents(); 
} 

/** 
* This method is called from within the constructor to initialize the form. 
* WARNING: Do NOT modify this code. The content of this method is always 
* regenerated by the Form Editor. 
*/ 
@SuppressWarnings("unchecked") 
// <editor-fold defaultstate="collapsed" desc="Generated Code">       
private void initComponents() { 

    jButton1 = new javax.swing.JButton(); 
    jTextField1 = new javax.swing.JTextField(); 

    setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); 

    jButton1.setText("jButton1"); 

    jTextField1.setText("jTextField1"); 

    javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); 
    getContentPane().setLayout(layout); 
    layout.setHorizontalGroup(
     layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 
     .addGroup(layout.createSequentialGroup() 
      .addContainerGap() 
      .addComponent(jButton1) 
      .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) 
      .addComponent(jTextField1, javax.swing.GroupLayout.DEFAULT_SIZE, 297, Short.MAX_VALUE) 
      .addContainerGap()) 
    ); 
    layout.setVerticalGroup(
     layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 
     .addGroup(layout.createSequentialGroup() 
      .addContainerGap() 
      .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) 
       .addComponent(jButton1) 
       .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) 
      .addContainerGap(266, Short.MAX_VALUE)) 
    ); 

    pack(); 
}// </editor-fold>       

/** 
* @param args the command line arguments 
*/ 
public static void main(String args[]) { 
    /* Set the Nimbus look and feel */ 
    //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) "> 
    /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel. 
    * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
    */ 
    try { 
     for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) { 
      if ("Nimbus".equals(info.getName())) { 
       javax.swing.UIManager.setLookAndFeel(info.getClassName()); 
       break; 
      } 
     } 
    } catch (ClassNotFoundException ex) { 
     java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); 
    } catch (InstantiationException ex) { 
     java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); 
    } catch (IllegalAccessException ex) { 
     java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); 
    } catch (javax.swing.UnsupportedLookAndFeelException ex) { 
     java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); 
    } 
    //</editor-fold> 

    /* Create and display the form */ 
    java.awt.EventQueue.invokeLater(new Runnable() { 
     public void run() { 
      new NewJFrame().setVisible(true); 
     } 
    }); 
} 

// Variables declaration - do not modify      
private javax.swing.JButton jButton1; 
private javax.swing.JTextField jTextField1; 
// End of variables declaration     


Scene scene = new Scene(root, 400, 300); 

}

答えて

0

あなたのコードが実行されない拡張し、 rootオブジェクトを初期化せず、JavaFXSwingソースコードと混ぜているためです。 JavaFXSwingは異なるGUIフレームワークです。

あなたはSwingアプリケーションを作成したい場合は、このチュートリアルに従うことができます:あなたがここに見つけることができますhttp://beginnersbook.com/2015/07/java-swing-tutorial/

JavaFXのサンプルアプリケーションを: http://docs.oracle.com/javafx/2/get_started/hello_world.htm

代わりにあなたがJFXPanel(JavaFXのを使用してJavaFXSwingを混在させることができますSwingアプリケーションでは、https://docs.oracle.com/javase/8/javafx/interoperability-tutorial/swing-fx-interoperability.htmを参照) およびSwingNode(JavaFXアプリケーションでのスイング、http://docs.oracle.com/javafx/8/embed_swing/jfxpub-embed_swing.htmを参照)。

関連する問題