Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set JavaFx ComboBox Font?

Im trying to change a ComboBox Font on JavaFx, so I have:

ComboBox cbCategoria = new ComboBox();

Im new in javaFx so some example code would be great :D, Is a Way to do it without CSS? and if not how can i make it with CSS,I havent learned how to use CSS Styling yet :(

like image 909
cefeboru Avatar asked Dec 27 '22 08:12

cefeboru


1 Answers

I think there is no way to do it without CSS. You can assign the style to that component as in the next sample:

VBox vbox = new VBox(10);
vbox.setAlignment(Pos.CENTER_LEFT);

ComboBox<String> noStyled = new ComboBox<>();
noStyled.getItems().addAll("One", "Two", "Three");

ComboBox<String> styled = new ComboBox<>();
styled.setPrefWidth(150);
styled.getItems().addAll("One", "Two", "Three");
styled.setStyle("-fx-font: 30px \"Serif\";");

vbox.getChildren().addAll(noStyled, styled);
Scene scene = new Scene(vbox);
stage.setScene(scene);
stage.show();

Or you can assign a stylesheet to an application. In both cases I recommend you to go through the tutorial CSS Section in the oracle web site and the reference guide.

Hope it helps.

like image 90
Antonio J. Avatar answered Jan 11 '23 03:01

Antonio J.