2016-09-30 177 views
0

我想我可以創建一個標籤,使用setFont(new Font(...)),然後在按鈕內部創建一個按鈕並使用.getText(),但它仍然看起來像default字體等設置按鈕內的文本大小

我將如何正確設置按鈕內的文本的字體?

Label startLabel = new Label("Start"); 
startLabel.setFont(new Font(26)); 
start = new Button(startL.getText()); 

我覺得這樣可行,但它和以前一樣。

+0

你能發表一些代碼嗎?真的不清楚你的意思。標籤和按鈕之間有什麼關係? –

+0

沒有任何代碼可以發佈。好的,所以你知道如何創建一個Label然後使用.setFont(double size)來編輯文本的大小。那麼我想知道是否可以用Button中的文本來做到這一點。 – zzzzzz

+0

當然是的。 –

回答

1

你需要

start = new Button("Start"); 
start.setFont(new Font(26)); 

你並不需要創建一個Label除非你確實在你的UI需要一個Label

1

1)可以使用css修改它,例如:

Button button = new Button("Some text"); 
button.setStyle("-fx-font-size:26px;"); //or (em) or.. 

2)可以爲圖形添加LabelButton(未 推薦)(一個好主意,例如在按鈕內添加一個 ProgressIndicator以顯示按下 按鈕時的一些進度

Label startLabel = new Label("Start"); 
    startLabel.setFont(new Font(26)); 
    Button start = new Button(""); //do not add Text to the Button 
    start.setGraphic(startLabel); 

3)使用的ButtonsetFont(...);方法。

Button button = new Button("Some text"); 
button.setFont(new Font(26));//you can play more with it creating custom fonts