0

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.

asked Sep 30, 2016 at 0:59
6
  • Can you post some code? It's really unclear what you mean. What's the relationship between the label and the button? Commented 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. Commented Sep 30, 2016 at 1:04
  • Well of course it is. Commented Sep 30, 2016 at 1:05
  • But how? I guess I should've said that instead of saying is it possible. Commented 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? Commented Sep 30, 2016 at 1:06

2 Answers 2

1

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.

answered Sep 30, 2016 at 1:12
Sign up to request clarification or add additional context in comments.

Comments

1

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 Label as a graphic to the Button(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 of Button.

 Button button = new Button("Some text");
 button.setFont(new Font(26));//you can play more with it creating custom fonts
answered Sep 30, 2016 at 1:44

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.