如何使用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 讲课祝福语简短10字
13 恭喜订婚的祝福语简短
14 高温早安祝福语简短精辟
15 升学祝福语简短的个性
16 考试祝福语简短给对象
17 简短正能量生日祝福语
18 步入高中祝福语简短励志