JavaFX UI组件——Cursor

 

import javafx.application.Application;
import javafx.geometry.Pos;
import javafx.scene.Cursor;
import javafx.scene.Node;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.layout.TilePane;
import javafx.stage.Stage;
 
/**
 * A sample that demonstrates changing the cursor icon.
 */
public class CursorApp extends Application {
 
    public Parent createContent() {
 
        TilePane tilePaneRoot = new TilePane(5, 5);
        tilePaneRoot.setMinSize(TilePane.USE_PREF_SIZE, TilePane.USE_PREF_SIZE);
        tilePaneRoot.setMaxSize(TilePane.USE_PREF_SIZE, TilePane.USE_PREF_SIZE);
        tilePaneRoot.setHgap(2);
        tilePaneRoot.setVgap(2);
        tilePaneRoot.getChildren().addAll(
                createBox(Cursor.DEFAULT),
                createBox(Cursor.CROSSHAIR),
                createBox(Cursor.TEXT),
                createBox(Cursor.WAIT),
                createBox(Cursor.SW_RESIZE),
                createBox(Cursor.SE_RESIZE),
                createBox(Cursor.NW_RESIZE),
                createBox(Cursor.NE_RESIZE),
                createBox(Cursor.N_RESIZE),
                createBox(Cursor.S_RESIZE),
                createBox(Cursor.W_RESIZE),
                createBox(Cursor.E_RESIZE),
                createBox(Cursor.OPEN_HAND),
                createBox(Cursor.CLOSED_HAND),
                createBox(Cursor.HAND),
                createBox(Cursor.DISAPPEAR),
                createBox(Cursor.MOVE),
                createBox(Cursor.H_RESIZE),
                createBox(Cursor.V_RESIZE),
                createBox(Cursor.NONE));
        return tilePaneRoot;
    }
 
    private Node createBox(Cursor cursor) {
        Label label = new Label(cursor.toString());
        label.setAlignment(Pos.CENTER);
        label.setPrefSize(85, 65);
        label.setStyle("-fx-border-color: #aaaaaa; -fx-background-color: #dddddd;");
        label.setCursor(cursor);
        return label;
    }
 
    @Override
    public void start(Stage primaryStage) throws Exception {
        primaryStage.setScene(new Scene(createContent()));
        primaryStage.show();
    }
 
    /**
     * Java main for when running without JavaFX launcher
     */
    public static void main(String[] args) {
        launch(args);
    }
}

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值