JavaFX:控件边框调整

样例,对Button变量的边框进行调整测试。

package ch06;

import javafx.application.Application;
import javafx.scene.control.Button;
import javafx.scene.layout.Border;
import javafx.scene.layout.BorderStroke;
import javafx.scene.layout.BorderStrokeStyle;
import javafx.scene.layout.BorderWidths;
import javafx.scene.layout.CornerRadii;
import javafx.scene.paint.Color;
import javafx.scene.paint.Paint;
import javafx.scene.shape.Rectangle;
import javafx.stage.Stage;
import javafx.scene.layout.HBox;
import javafx.scene.Scene;

/**
 * @copyright 2023-2022
 * @package   ch06
 * @file      ResizeNodeTest.java
 * @date      2023-08-19 19:22
 * @author    qiao wei
 * @version   1.0
 * @brief     
 * @history
 */
public class ResizeNodeTest extends Application {
    
    public static void main(String[] args) {
        Application.launch(ResizeNodeTest.class, args);
    }
    
    @Override
    public void start(Stage stage) throws Exception {
        Button button = new Button("A big button");
        BorderStroke borderStroke =
            new BorderStroke(Paint.valueOf("#FF0000"),
                // 控件边框线条。
                BorderStrokeStyle.SOLID,
                // 控件边框角度。
                new CornerRadii(20),
                // 控件边框宽度
                new BorderWidths(30));
        button.setBorder(new Border(borderStroke));
        
        Rectangle rect = new Rectangle(100, 50);
        rect.setFill(Color.PINK);
        // 设置控件边宽和颜色。
        rect.setStrokeWidth(1);
        rect.setStroke(Color.GREEN);
        
        HBox root = new HBox(2);
        root.getChildren().addAll(button, rect);
        Scene scene = new Scene(root);
        stage.setScene(scene);
        stage.setTitle("Resizable Nodes");
        stage.show();
        
        System.out.println("btn.isResizable(): " + button.isResizable());
        System.out.println("rect.isResizable(): " + rect.isResizable());
    }
}

你可能感兴趣的:(JavaFX,Java,前端,java,javafx)