代码之家  ›  专栏  ›  技术社区  ›  Justin

JavaFX中的标签间距

  •  -1
  • Justin  · 技术社区  · 7 年前


    我可以很好地为标签做广告,但是,我不能在每一个标签之间休息。以下是我已经尝试过的事情:

    1. 正在寻找一个带有css的选项 -fx-display

    2. 添加换行符 \n 或前后两个或前后两个的字符串。

    3. 改变 \不 包括其他换行符,例如 <br>

    4. 仅为换行文字添加单独的标签。

    5. 从BorderPane、FlowPane和VBox更改布局。

    6. 将setWrapText()设置为true或false。

    是的,文本显示正确,我已经打印了所有内容,看起来都很好。

    Screenshot

    1 回复  |  直到 7 年前
        1
  •  0
  •   c0der    7 年前

    这可能有助于:

    import javafx.application.Application;
    import javafx.scene.Scene;
    import javafx.scene.control.Button;
    import javafx.scene.control.Label;
    import javafx.scene.layout.BorderPane;
    import javafx.scene.layout.TilePane;
    import javafx.stage.Stage;
    
    public class FxTest extends Application {
    
        private static int counter = 0;
    
        @Override
        public void start(Stage primaryStage)throws Exception{
    
            TilePane main = new TilePane();
            main.setPrefColumns(8); 
            main.setHgap(10);  main.setVgap(10); //veritcal and horizontal space 
    
            Button add = new Button("Add");
            add.setOnAction(e -> main.getChildren().add(new Label("Lable "+ counter ++)));
    
            BorderPane root = new BorderPane(main);
            root.setBottom(add);
            Scene scene = new Scene(root,400,400);
            primaryStage.setScene(scene);
            primaryStage.show();
        }
    
        public static void main(String[] args) {
            launch(null);
        }
    }
    
    推荐文章