2017-12-07 11 views
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

enter image description here

私はcellsCountLabel.setWrapText(true)を使用してみましたが、それはうまくいきませんでした。

+0

https://stackoverflow.com/questions/36344916/wrapping-label-text-in-a-vbox-using-fxmlをご覧ください。 –

+0

prefWidthを設定する必要があります。 –

+0

@Ralf Renz 'Labels 'で' setupsPane'に?すでに行った...または 'Label'自体に? – parsecer

答えて

0

あなたはこのルートを行く場合は、後で使用するために

をこの

static double sidePaneWidth = (gameWidth-400)/2; 

のようなものを宣言したいことがあります。また、同様の機能にこれを行うことができます。また、この

Label label = new Label("Setups Panel1111115552222222133331111"); 
label.setWrapText(true); 
label.setMaxWidth((gameWidth-400)/2); 
setupsPane.getChildren().add(label); 

をお試しください従って必要ならば

private Label newSidePaneLabel(String labelString){ 
    Label label = new Label(labelString); 
    label.setWrapText(true); 
    label.setMaxWidth(sidePaneWidth); 
    return label; 
} 
関連する問題