私は JavaFx を学習し、レストランのメニュー項目のリストをスクロール可能な方法で表示するサンプル アプリを作成しています。これを行う最善の方法は、controlsfx の GridView コントロールを使用することであることがわかりました。これは、大量のメニュー項目のセットでもスクロールが高速に動作するためです。これを機能させようとしているサンプルコードを次に示します。
public class Main extends Application {
@Override
public void start(Stage primaryStage) {
try {
VBox root = new VBox();
Scene scene = new Scene(root,400,400);
scene.getStylesheets().add(getClass().getResource("application.css").toExternalForm());
primaryStage.setScene(scene);
ObservableList<GridPane> list = FXCollections.<GridPane>observableArrayList();
GridView<GridPane> gridView = new GridView<>(list);
gridView.setCellFactory(new Callback<GridView<GridPane>, GridCell<GridPane>>() {
public GridCell<GridPane> call(GridView<GridPane> gridView) {
return new GridCell<GridPane>();
}
});
Label lblName1 = new Label("Name");
GridPane grid = new GridPane();
grid.addRow(0, lblName1);
Label lblName2 = new Label("Price");
grid.addRow(1, lblName2);
list.add(grid);
root.getChildren().add(gridView);
primaryStage.show();
} catch(Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
launch(args);
}
}
上記のコードを実行すると、アイテムのない VBox のみが表示されます。GridView ( http://controlsfx.bitbucket.org/org/controlsfx/control/GridView.html )を使用して、controlsfx Web サイトにあるサンプル コードを複製しようとしました。
ヘルプ/ヒントをいただければ幸いです。ありがとう。