このコードでは、私のウィンドウに線を描画することはできません... 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
}
}
ポストのような完全なパッケージパスとFXML
設定Controllerクラスを使用するにアプリケーションの残りの部分を使用して
( FXMLファイルとアプリケーションクラス)。あなたがそれを実行するときにエラーが発生しますか? –
@James_D私の問題とより多くのコードに関する情報を追加しました。 –