codecamp

JavaFX 分隔符

JavaFX教程 - JavaFX分隔符


Separator类表示水平或垂直分隔线。它分割元素,不产生任何动作。

我们可以设计风格,应用视觉效果,并为分隔符设置动画。

默认情况下,分隔符是水平的。我们可以使用setOrientation方法改变它的方向。

Separator类扩展了Node类。

创建分隔符

创建水平分隔符

Separator separator1 = new Separator();

创建垂直分隔符

Separator separator2 = new Separator();
separator2.setOrientation(Orientation.VERTICAL);

setMaxWidth方法定义了一个特定的宽度。

setValignment方法指定垂直位置。

例子

带分隔符的标签

import javafx.application.Application;
import javafx.geometry.Insets;
import javafx.geometry.VPos;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.control.Separator;
import javafx.scene.layout.GridPane;
import javafx.scene.text.Font;
import javafx.stage.Stage;

public class Main extends Application {

    Label caption = new Label("We");

    @Override
    public void start(Stage stage) {
        Group root = new Group();
        Scene scene = new Scene(root, 500, 200);
        stage.setScene(scene);

        GridPane grid = new GridPane();
        grid.setPadding(new Insets(10, 10, 10, 10));
        grid.setVgap(2);
        grid.setHgap(5);

        scene.setRoot(grid);

        caption.setFont(Font.font("Verdana", 20));

        GridPane.setConstraints(caption, 0, 0);
        GridPane.setColumnSpan(caption, 8);
        grid.getChildren().add(caption);

        final Separator sepHor = new Separator();
        sepHor.setValignment(VPos.CENTER);
        GridPane.setConstraints(sepHor, 0, 1);
        GridPane.setColumnSpan(sepHor, 7);
        grid.getChildren().add(sepHor);

        stage.show();
    }
    public static void main(String[] args) {
        launch(args);
    }
}

上面的代码生成以下结果。

null


JavaFX 工具提示
JavaFX 组合框
温馨提示
下载编程狮App,免费阅读超1000+编程语言教程
取消
确定
目录

JavaFX 效果

JavaFX 主题

JavaFX 转换

关闭

MIP.setData({ 'pageTheme' : getCookie('pageTheme') || {'day':true, 'night':false}, 'pageFontSize' : getCookie('pageFontSize') || 20 }); MIP.watch('pageTheme', function(newValue){ setCookie('pageTheme', JSON.stringify(newValue)) }); MIP.watch('pageFontSize', function(newValue){ setCookie('pageFontSize', newValue) }); function setCookie(name, value){ var days = 1; var exp = new Date(); exp.setTime(exp.getTime() + days*24*60*60*1000); document.cookie = name + '=' + value + ';expires=' + exp.toUTCString(); } function getCookie(name){ var reg = new RegExp('(^| )' + name + '=([^;]*)(;|$)'); return document.cookie.match(reg) ? JSON.parse(document.cookie.match(reg)[2]) : null; }