[英]How to set a text inside a button to drop the shadow in JavaFX
所以我在控制器中有一個自定義按鈕類,我想制作將在按鈕里面放置陰影的字體。 我試過使用-fx-stroke,但它似乎沒有改變任何東西。 我想要使用的按鈕將在程序期間生成。 我不熟悉CSS所以我只是用了一些例子。 現在我有了這個
mineButton(int x, int y,boolean difficult){
this.x=x;
this.y=y;
Font s = new Font(13);
if (difficult){
this.setMaxSize(35, 35);
this.setMinSize(20, 20);
this.setPrefSize(20, 20);
this.setFont(new Font(8));
} else {
this.setMaxSize(35,35);
this.setMinSize(33,33);
this.setPrefSize(34,34);
}
this.setStyle("-fx-background-color: -fx-outer-border,
-fx-inner-border, -fx-body-color;\n" +
" -fx-background-insets: 0, 1, 2;" +
" -fx-background-radius: 5, 4, 3;" +
" -fx-text-fill: white; -fx-font-weight: bold;" );
}
您可以使用setGraphic方法更改Button內Node的外觀。
這是一個文檔,其中包含有關如何執行此操作的示例: 使用JavaFX UI控件 - 按鈕 。
然后,您可以將CSS應用於您的自定義節點。
例:
Button button = new Button();
Label label = new Label("Click Me!");
label.setStyle("-fx-effect: dropshadow( one-pass-box , black , 8 , 0.0 , 2 , 0 )");
button.setGraphic(label);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.