• JavaFX:Insets在控件中使用简例


    Insets是矩形区域 4 边的一组内偏移量,矩形内的设置与边框距离。如果在周围的边框有控件,则是矩形与控件的距离。

    1. package javafx8.ch10;
    2. import javafx.application.Application;
    3. import javafx.geometry.Insets;
    4. import javafx.scene.Scene;
    5. import javafx.scene.control.Button;
    6. import javafx.scene.layout.Background;
    7. import javafx.scene.layout.BackgroundFill;
    8. import javafx.scene.layout.Border;
    9. import javafx.scene.layout.BorderStroke;
    10. import javafx.scene.layout.BorderStrokeStyle;
    11. import javafx.scene.layout.BorderWidths;
    12. import javafx.scene.layout.CornerRadii;
    13. import javafx.scene.layout.HBox;
    14. import javafx.scene.paint.Paint;
    15. import javafx.stage.Stage;
    16. /**
    17. * @copyright 2023-2022
    18. * @package javafx8.ch10
    19. * @file InsetsTest.java
    20. * @date 2023-08-25 12:46
    21. * @author qiao wei
    22. * @version 1.0
    23. * @brief
    24. * @history
    25. */
    26. public class InsetsTest extends Application {
    27. public InsetsTest() {}
    28. @Override
    29. public void start(Stage primaryStage) throws Exception {
    30. /**
    31. *
    32. */
    33. Button button = new Button("Insets Test");
    34. button.setBorder(
    35. new Border(
    36. new BorderStroke(
    37. null,
    38. BorderStrokeStyle.SOLID,
    39. null,
    40. new BorderWidths(1),
    41. new Insets(2)
    42. )
    43. )
    44. );
    45. Button button01 = new Button("Insets02");
    46. button01.setBorder(
    47. new Border(
    48. new BorderStroke(
    49. null,
    50. BorderStrokeStyle.DASHED,
    51. new CornerRadii(10),
    52. new BorderWidths(2),
    53. new Insets(5)
    54. )
    55. )
    56. );
    57. // button.setBackground(
    58. // new Background(
    59. // new BackgroundFill(
    60. // Paint.valueOf("#8FBC8F"),
    61. // null,
    62. // Insets.EMPTY
    63. // )
    64. // )
    65. // );
    66. HBox hBox = new HBox();
    67. // 设置控件button在hBox中与边距的设置。因为button右侧有控件button1,则右侧边距为与控件button1的距离。
    68. HBox.setMargin(button, new Insets(5, 10, 150, 10));
    69. hBox.getChildren().addAll(button, button01);
    70. hBox.setBackground(
    71. new Background(
    72. new BackgroundFill(Paint.valueOf("#54FF9F"),
    73. null,
    74. null
    75. )
    76. )
    77. );
    78. Scene scene = new Scene(hBox);
    79. primaryStage.setScene(scene);
    80. primaryStage.show();
    81. }
    82. public static void main(String[] args) {
    83. try {
    84. Application.launch(InsetsTest.class, args);
    85. } catch (Exception exception) {
    86. exception.printStackTrace();
    87. }
    88. }
    89. }

    测试结果如下:

  • 相关阅读:
    24-Vue之过滤器基本用法
    Web前端小组考核总结
    设计模式:责任链模式
    You can’t specify target table ‘xxx’ for update in FROM clause
    关于A-level选课的6个建议
    c sharp基于随笔画的加解密系统
    springboot基于Java的电影院售票与管理系统毕业设计源码011449
    第一次小实习记录
    电脑更换硬盘的时候怎么迁移系统?
    STM32单片机OLED贪吃蛇游戏记分计时
  • 原文地址:https://blog.csdn.net/weiweiqiao/article/details/133589449