2015-02-07 27 views
1

因此,我在控制器中有一個自定義按鈕類,並且我想使字體在按鈕內部放置陰影。我試過使用-fx-stroke,但它似乎沒有改變任何東西。我想要使​​用的按鈕將在程序中生成。我不熟悉CSS,所以我只是用了一些例子。現在我有這個如何在按鈕中設置文本以放棄JavaFX中的陰影

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;"); 
    } 
+0

添加筆劃字體將還不錯 – 2015-02-07 13:01:00

回答

2

您可以使用setGraphic方法來更改您的按鈕內節點的外觀。

下面是關於如何操作的示例文檔:Using JavaFX UI Controls - Button

然後,您可以將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); 
+0

我要感謝你 – 2015-02-09 09:20:53