2015-02-07 58 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