1
私は、BorderPane
には、Pane
(左、右、中央の要素)、HBox
(上の要素)があります。右のPane
にはLabel
があります。 Label
にはテキストが含まれています。テキストは折り返されずに切り取られます。JavaFx:ラベルテキストが折り返さない
public class Main extends Application implements EventHandler<ActionEvent> {
private static BorderPane gamePane;
private static Pane cellsPane;
private static HBox buttonsPane;
private static Pane statsPane;
private static Pane setupsPane;
Label cellsCountLabel;
static int gameWidth= 700;
static int gameHeight=600;
@Override
public void start(Stage primaryStage) throws Exception {
primaryStage.setTitle("Hello World");
gamePane = new BorderPane();
buttonsPane = new HBox(5);
statsPane = new Pane();
cellsPane = makeGrid(20);
setupsPane = new Pane();
cellsPane.setStyle("-fx-background-color: #ffffff; -fx-border-color: black");
buttonsPane.setStyle("-fx-background-color: #f2f2f2; -fx-border-color: black");
statsPane.setStyle("-fx-background-color: #f2f2f2; -fx-border-color: black");
setupsPane.setStyle("-fx-background-color: #f2f2f2; -fx-border-color: black");
cellsPane.setMaxWidth(400);
statsPane.setMaxWidth((gameWidth-400)/2);
setupsPane.setMaxWidth((gameWidth-400)/2);
createCellButton = new Button();
deleteCellsButton = new Button();
createCellButton.setText("Create a cell");
deleteCellsButton.setText("Delete cells");
...
buttonsPane.setSpacing(10);
buttonsPane.setPadding(new Insets(10, 10, 10, 10));
buttonsPane.getChildren().add(createCellButton);
buttonsPane.getChildren().add(deleteCellsButton);
gamePane.setTop(buttonsPane);
gamePane.setCenter(cellsPane);
...
cellsCountLabel = new Label("Cells Count: " + (cellId + 1));
statsPane.getChildren().add(cellsCountLabel);
gamePane.setLeft(statsPane);
setupsPane.getChildren().add(new Label("Setups Panel1111115552222222133331111"));
gamePane.setRight(setupsPane);
gamePane.setMargin(statsPane, new Insets(0, 0, 0, 0));
gamePane.setMargin(cellsPane, new Insets(0,0,0,0));
gamePane.setMargin(setupsPane, new Insets(0,0,0,0));
statsPane.setPrefWidth(150);
setupsPane.setPrefWidth(150);
cellsCountLabel.setWrapText(true); //doesn't work
Scene scene = new Scene(gamePane, gameWidth, gameHeight);
primaryStage.setScene(scene);
...
primaryStage.show();
}
...
}
ただし、左、中央と右の間にスペースがあります。Pane
です。それらのコンテンツが大きくなるにつれて空間は小さくなりますが、大きすぎると中心がくすぶりますPane
。
私はcellsCountLabel.setWrapText(true)
を使用してみましたが、それはうまくいきませんでした。
https://stackoverflow.com/questions/36344916/wrapping-label-text-in-a-vbox-using-fxmlをご覧ください。 –
prefWidthを設定する必要があります。 –
@Ralf Renz 'Labels 'で' setupsPane'に?すでに行った...または 'Label'自体に? – parsecer