如何使用JavaFX创建ScrollBar?
滚动条包含附加到可滚动窗格的拇指,左右按钮。使用此功能,您可以上下滚动窗格(附加到窗格)。
在JavaFX中,javafx.scene.control.ScrollBar表示滚动条。您可以创建一个实例化此类的滚动条。
您可以创建垂直或水平滚动条,默认情况下会创建一个水平滚动条,您可以使用setOrientation()方法将其更改为垂直滚动条。
通常,滚动条与其他控件关联,例如ScrollPane,ListView等。
示例
import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.control.ScrollBar;
import javafx.scene.paint.Color;
import javafx.scene.text.Font;
import javafx.scene.text.FontPosture;
import javafx.scene.text.FontWeight;
import javafx.stage.Stage;
public class ScrollBarExample extends Application {
public void start(Stage stage) {
//教育标签
Label label = new Label("学历:");
Font font = Font.font("verdana", FontWeight.BOLD, FontPosture.REGULAR, 12);
label.setFont(font);
//列表查看学历
ScrollBar scroll = new ScrollBar();
scroll.setMin(0);
scroll.setMax(400);
scroll.setValue(50);
//设置滚动窗格的位置
scroll.setLayoutX(180);
scroll.setLayoutY(75);
//设置舞台
Group root = new Group(scroll);
Scene scene = new Scene(root, 595, 200, Color.BEIGE);
stage.setTitle("List View Example");
stage.setScene(scene);
stage.show();
}
public static void main(String args[]){
launch(args);
}
}输出结果
热门推荐
10 钢琴人祝福语女生简短
11 岗位考试顺利祝福语简短
12 关于老师蛋糕祝福语简短
13 娘家妈妈新婚祝福语简短
14 生日留言简短祝福语大全
15 祝福语诗意文案简短
16 校长退休文案祝福语简短
17 宝子生日祝福语简短
18 寒露祝福语毕业寄语简短