2017-07-26 11 views
2

このコードでは、私のウィンドウに線を描画することはできません... fxmlファイルにあるすべてのものは、fx:id of hiを使った簡単なペインです。エラーはなく、行は単に表示されません。私もボックスとサークルでこれを試しました。私は本当に助けが必要です、これは重要なプロジェクトです。pane.getChildren()。addAll(); javafx

import java.net.URL; 
import java.util.ResourceBundle; 
import javafx.fxml.FXML; 
import javafx.fxml.Initializable; 
import javafx.scene.layout.AnchorPane; 
import javafx.scene.layout.BorderPane; 
import javafx.scene.layout.Pane; 
import javafx.scene.shape.Line; 
import javafx.scene.Scene; 
import javafx.scene.paint.Color; 

public class PlotSceneController implements Initializable { 

    @FXML 
    Pane hi; 

    @Override 
    public void initialize(URL url, ResourceBundle rb) { 

    Line line = new Line(0,0,10,110); 
     line.setStroke(Color.BLACK); 
     line.setStrokeWidth(10); 
     hi.getChildren().addAll(line); 

    } 

} 

FXMLファイル

<?xml version="1.0" encoding="UTF-8"?> 

<?import javafx.scene.shape.*?> 
<?import java.lang.*?> 
<?import java.net.*?> 
<?import java.util.*?> 
<?import javafx.scene.*?> 
<?import javafx.scene.control.*?> 
<?import javafx.scene.layout.*?> 


<Pane fx:id="hi" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="- 
Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" 
xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1"> 
<children> 

</children> 
</Pane> 

メイン・クラスは、私はとのトラブルを抱えているページにつながるボタンで別のページにつながります。

public class Main extends Application { 

Stage firstStage; 
Scene loginButton; 

@Override 
public void start(Stage primaryStage) throws Exception {    

    Parent root = FXMLLoader.load(getClass().getResource("Main.fxml")); 
    firstStage = primaryStage;     
    loginButton = new Scene(root, 900, 700);  

    primaryStage.setTitle("Treatment Data");    
    primaryStage.setScene(loginButton);   
    primaryStage.show();       
} 

/** 
* @param args the command line arguments 
*/ 
public static void main(String[] args) {  //Main class 
    launch(args);      //Launches application/window 
} 

}

+0

ポストのような完全なパッケージパスとFXML

設定Controllerクラスを使用するにアプリケーションの残りの部分を使用して

( FXMLファイルとアプリケーションクラス)。あなたがそれを実行するときにエラーが発生しますか? –

+0

@James_D私の問題とより多くのコードに関する情報を追加しました。 –

答えて

5

あなたは、コントローラクラスPlotSceneController.javaを設定するために逃しています。メインクラスのsetController()メソッドを使用するか、シーンビルダー画面の左下のコントローラーペインにコントローラークラスを設定するかのように、コントローラークラスを異なる2つの方法で設定します。メイン

FXMLLoader loader = new FXMLLoader(getClass().getResource("Main.fxml")); 
loader.setController(new PlotSceneController()); 
Parent root = (Parent) loader.load(); 

または、下記の方法

enter image description here

+0

それはとてもばかげてシンプルですが、私はそれを逃したとは思えません。どうもありがとう! –

関連する問題