How to put custom fonts in a combobox in JavaFX?

There is a label with text and a combobox in the application. When I click on the combobox comes up the list of fonts. When you click on a font, the font of the text label is changed to selected. At the moment I have the combobox working fine but there only displays the fonts that are installed in the system(WIndows/fonts) I need to combobox to display only the fonts from the folder, which is located in the program folder.
System - Windows 10

How to post custom fonts in a combobox?

If the combobox is not possible to put your custom fonts folder, it is possible to change the path to the system folder with fonts?

@FXML private ComboBox<Font> fontSelector;
@FXML private Label fontLabel;

//get font family and size 
 private static Font getFont(Font Font, Integer size) {
 return Font.font(font == null ? null : font.getFamily(), size == null ? -1d : size.doubleValue());
}

//add font families to combboox
 fontSelector.getItems().addAll(Font.getFamilies().stream().map(name -> Font.font(name, 14)).toArray(Font[]::new));

// bind based on font size/family
fontLabel.fontProperty()
 .bind(Bindings.createObjectBinding(() -> getFont(fontSelector.getValue(), size.getValue()),
 fontSelector.valueProperty(), size.valueProperty()));

//render and display font for Mac looks in the combobox
 FontListCell class extends ListCell<Font> {
@Override
 public void updateItem(item, Font, boolean empty) {
 super.updateItem(item, empty);
 if (item != null) {
setText(item.getFamily());
setFont(item);
 } else {
setText("");
setFont(Font.font(12));
}
}
}

 fontSelector.setCellFactory(lv -> new FontListCell());
 fontSelector.setButtonCell(new FontListCell());


Project structure:

5cf6786155b1a028702178.jpeg
March 23rd 20 at 19:03
0 answer

Find more questions by tags JavaFXJava