P
P
postya2019-04-04 07:15:12
Java
postya, 2019-04-04 07:15:12

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();
}

The font is stored in the .properties file like this:
5ca583a74fe98944498420.jpegHow can I apply this font from the properties file to the label?
I tried to do the following:
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");
    }
  }

But an error appears:
5ca5847c12c00283943073.jpeg

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
sergey, 2019-04-05
@postya

it says it wants a colon where you have an equals sign..

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question