JavaFX学习 自定义分页,工具栏,window

这是很多都是借鉴别人的。
用Button实现关闭Icon,最小化Icon,最大化Icon
[img]http://dl.iteye.com/upload/attachment/0078/5669/e0d09ab0-e8e2-30f5-98aa-405529ed4a5c.png[/img]

public class TestButton extends Application {

double width = 600;
double height = 300;
Stage stage;
double offsetX;
double offsetY;

@Override
public void start(Stage stage) throws Exception {

VBox root = new VBox();
init(root);
Scene scene = new Scene(root, width, height);
scene.getStylesheets().add(getClass().getResource("dialogs.css").toExternalForm());
Stage subStage = new Stage(StageStyle.TRANSPARENT);
subStage.initOwner(stage);
subStage.setScene(scene);
subStage.show();
this.stage = subStage;
}

public void init(VBox root) {
HBox box = new HBox(10);
ToolBar tb = new ToolBar();
Button closeButton = createButton("close");
closeButton.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
stage.close();
}
});
Button minimizeButton = createButton("minimize");
minimizeButton.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
stage.setIconified(!stage.isIconified());
}
});

Button maximizeButton = createButton("maximize");
maximizeButton.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
stage.setFullScreen(true);
}
});
box.getChildren().addAll(minimizeButton,maximizeButton,closeButton);
Region region = new Region();
HBox.setHgrow(region, Priority.ALWAYS);
tb.getItems().addAll(region,box);
tb.setOnMousePressed(new EventHandler<MouseEvent>() {
@Override
public void handle(MouseEvent event) {
offsetX = event.getSceneX();
offsetY = event.getSceneY();
}
});
tb.setOnMouseDragged(new EventHandler<MouseEvent>() {
@Override
public void handle(MouseEvent event) {
stage.setX(event.getScreenX()-offsetX);
stage.setY(event.getScreenY()-offsetY);
}
});
HBox center = new HBox();
center.setStyle("-fx-background-color: #949494");
VBox.setVgrow(center, Priority.ALWAYS);
root.getChildren().addAll(tb,center);
}

public Button createButton(String name){
StackPane graphic = new StackPane();
graphic.getStyleClass().setAll("graphic");
Button button = new Button();
button.getStyleClass().setAll("window-button");
button.getStyleClass().add("window-"+name+"-button");
button.setGraphic(graphic);
button.setMinSize(17, 17);
button.setPrefSize(17, 17);
return button;
}
public static void main(String args[]) {
launch();
}
}


.window-button {
-fx-skin: "com.sun.javafx.scene.control.skin.ButtonSkin";
-fx-background-color: transparent transparent;
-fx-background-insets: 0, 1;
-fx-background-radius: 2;
-fx-padding: 0 0 0 0;
-fx-alignment: center;
}

.window-button:hover {
-fx-background-color: linear-gradient(#505050,#2d2d2d),
linear-gradient(#a3a3a3, #8b8b8b 34%, #777777 36%, #777777 63%, #8b8b8b 65%, #adadad);
}

.window-button:pressed {
-fx-background-color: linear-gradient(#515151,#202020),
linear-gradient(#a3a3a3, #8b8b8b 34%, #777777 36%, #777777 63%, #8b8b8b 65%, #adadad);
}

.window-button .graphic {
-fx-background-color: #949494;
-fx-scale-shape: false;
-fx-padding: 4.5 4.5 4.5 4.5; /* Graphic is 9x9 px */
}

.window-button:hover .graphic {
-fx-background-color: #fefeff;
}

.window-button:pressed .graphic {
-fx-background-color: #cfcfcf;
}

.window-close-button .graphic {
-fx-shape: "M395.992,296.758l1.794-1.794l7.292,7.292l-1.795,1.794 L395.992,296.758z M403.256,294.992l1.794,1.794l-7.292,7.292l-1.794-1.795 L403.256,294.992z";
}

.window-minimize-button .graphic {
-fx-shape: "M420.012,299.248v2.537h-9.001v-2.537H420.012z";
}

.window-maximize-button .graphic {
-fx-shape: "M406.283,294.985h2.537v9.031h-2.538L406.283,294.985z M412.012,298.248v2.537h-9.001v-2.537H412.012z";
}



分页Button
[img]http://dl.iteye.com/upload/attachment/0078/5673/209e2327-85b8-3e20-8178-7de3f8af0c92.png[/img]


工具栏ToolBar
[img]http://dl.iteye.com/upload/attachment/0078/6417/94c2e5d9-bf0a-35d8-abfc-daa7d4d96842.png[/img]

这里有个javafx学习的中文网站,我把内容都丢那上面去了。
http://www.jfxee.com/
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值