Answer the question
In order to leave comments, you need to log in
How to apply font from .properties file to label in Java program?
There is a label from which I get the font (font name, family, font style and size) and save it to the properties file.
I do it like this:
@FXML
void applyFont(ActionEvent event) throws FileNotFoundException, IOException {
FileInputStream in = new FileInputStream("config.properties");
Properties properties = new Properties();
properties.load(in);
in.close();
FileOutputStream fos = new FileOutputStream("config.properties");
properties.setProperty("categoryFont1", fontLabel.getFont().toString());
properties.store(fos, null);
fos.close();
}
private void readPropertiesFile() {
try {
File file = new File("config.properties");
FileInputStream fileInput = new FileInputStream(file);
Properties properties = new Properties();
properties.load(fileInput);
fileInput.close();
String categoryFont1 = properties.getProperty("categoryFont1");
category1.setStyle(categoryFont1);
} catch (FileNotFoundException e) {
System.out.println("File not found");
} catch (IOException e) {
System.out.println("No such file");
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question