Sagir:
私は、テキストは、テキストがgridPane、代わりのScrollPaneのうちに行くべきではない増加した場合、私は箱の側面から、アップルのテキストを行くのを見たくないしたい、子供GridPaneを持っています。
@Override
public void start(Stage primaryStage) throws Exception {
String border = "-fx-border-color:red;";
Text title=new Text("Machin");
GridPane topLeft=new GridPane();
topLeft.setMinSize(80, 5);
topLeft.setMaxSize(80, 80);
topLeft.setStyle(border);
topLeft.add(title, 0, 0);
for(int i=1;i<=15;i++) {
topLeft.add(new Text("Apple"), 0,i);
}
GridPane root = new GridPane();
root.setAlignment(Pos.CENTER);
root.setHgap(20);
root.setVgap(20);
root.add(topLeft, 0, 0);
BorderPane borderPane = new BorderPane();
borderPane.setTop(new Label("Header"));
borderPane.setCenter(root);
borderPane.setBottom(new Label("Buttom"));
primaryStage.setScene(new Scene(borderPane, 600, 400));
primaryStage.show();
}
画像:
jewelsea:
むしろのようなレイアウトペインよりGridPane、次のような、より洗練されたコントロールの一部を使用することができ、リストビューまたはテーブルビューをあなたのコンテンツを同封します。これらのコントロールは、内蔵のコントロールの内容が表示可能領域よりも大きい場合に表示されますスクロールバーがあります。これらの他のコントロールがアプリケーションに適用されるかどうかを評価するためにリンクのチュートリアルを確認します。
あなたが保持したい場合はGridPane
、あなたがラップすることができますGridPane
でのScrollPaneのコンテンツを許可するGridPane
ことは、そのようなサンプル以下のように一定のサイズに達した場合にスクロールします:
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.*;
import javafx.scene.layout.*;
import javafx.scene.text.Text;
import javafx.stage.Stage;
public class ScrollingGrid extends Application {
@Override
public void start(Stage primaryStage) throws Exception {
String border = "-fx-border-color:red;";
Text title = new Text("Machin");
GridPane appleGrid = new GridPane();
appleGrid.setMinSize(80, 5);
appleGrid.setStyle(border);
appleGrid.add(title, 0, 0);
for (int i = 1; i <= 15; i++) {
appleGrid.add(new Text("Apple"), 0, i);
}
ScrollPane scrollPane = new ScrollPane(appleGrid);
scrollPane.setPrefViewportWidth(80);
scrollPane.setPrefViewportHeight(80);
scrollPane.setMaxSize(ScrollPane.USE_PREF_SIZE, ScrollPane.USE_PREF_SIZE);
BorderPane borderPane = new BorderPane();
borderPane.setTop(new Label("Header"));
borderPane.setCenter(scrollPane);
borderPane.setBottom(new Label("Bottom"));
primaryStage.setScene(new Scene(borderPane, 600, 400));
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}