I figured I could create a label, use setFont(new Font(...)), then create a button and use .getText() inside of the Button but it still looks like default fonts etc.
How would I correctly set the font of text inside of a Button?
Label startLabel = new Label("Start");
startLabel.setFont(new Font(26));
start = new Button(startL.getText());
I figured that would work, but it stayed the same as before.
-
Can you post some code? It's really unclear what you mean. What's the relationship between the label and the button?James_D– James_D2016年09月30日 01:00:07 +00:00Commented Sep 30, 2016 at 1:00
-
There's not really any code to post. Okay, so you know how you can create a Label then use .setFont(double size) to edit the size of the text. Well I was wondering if it would be possible to do that with the text inside of a Button.zzzzzz– zzzzzz2016年09月30日 01:04:55 +00:00Commented Sep 30, 2016 at 1:04
-
Well of course it is.James_D– James_D2016年09月30日 01:05:39 +00:00Commented Sep 30, 2016 at 1:05
-
But how? I guess I should've said that instead of saying is it possible.zzzzzz– zzzzzz2016年09月30日 01:06:09 +00:00Commented Sep 30, 2016 at 1:06
-
Exactly the same way. If you have tried it, post your attempted code and explain what goes wrong. If you haven't tried it, why are you posting here?James_D– James_D2016年09月30日 01:06:57 +00:00Commented Sep 30, 2016 at 1:06
2 Answers 2
You need
start = new Button("Start");
start.setFont(new Font(26));
You don't need to create a Label unless you actually need a Label in your UI.
Comments
1)You can modify it with
css,for example:
Button button = new Button("Some text");
button.setStyle("-fx-font-size:26px;"); //or (em) or..
2)You can add the
Labelas a graphic to theButton(not recommended)(a good idea for that would be for example to add a ProgressIndicator inside a Button to show some progress when the Button is pressed)
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)Use
setFont(...);method ofButton.
Button button = new Button("Some text");
button.setFont(new Font(26));//you can play more with it creating custom fonts