I want this part of my code with different languge so I am using bundles. I am trying to set the value of text in fxml file with "%" sign to have the value in the bundle.properties file.
I have the following code in the fxml file using Scenebuilder:
<?xml version="1.0" encoding="UTF-8"?>
<?import de.jensd.fx.glyphs.fontawesome.FontAwesomeIcon?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.layout.VBox?>
<VBox fx:id="iconBox" alignment="CENTER" maxHeight="-Infinity" maxWidth="-
Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="80.0"
prefWidth="80.0" xmlns="http://javafx.com/javafx/18"
xmlns:fx="http://javafx.com/fxml/1"
fx:controller="com.sarf.main.HomeIconsController">
<children>
<FontAwesomeIcon fx:id="iconName" glyphName="STAR" size="26" />
<Label fx:id="iconLabel" text="%anyThing">
<opaqueInsets>
<Insets />
</opaqueInsets>
<VBox.margin>
<Insets top="20.0" />
</VBox.margin>
</Label>
</children>
</VBox>
I am using properties file and trying to set the value of the text from the Controller of the fxml file. here is the code in the controller:
package com.sarf.main;
import com.sarf.main.models.HomeIcon;
import de.jensd.fx.glyphs.fontawesome.FontAwesomeIcon;
import java.net.URL;
import java.util.ResourceBundle;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Label;
//import javafx.scene.layout.VBox;
public class HomeIconsController implements Initializable{
//@FXML
//private VBox iconBox;
@FXML
private FontAwesomeIcon iconName;
@FXML
private Label iconLabel;
@Override
public void initialize(URL url, ResourceBundle rb) {
iconLabel.setText("%grocery");
}
}
the main.java file:
package com.sarf.main;
import java.io.IOException;
import java.util.Locale;
import java.util.ResourceBundle;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;
import java.sql.*;
public class Main extends Application {
@Override
public void start(Stage primaryStage) throws IOException {
Locale local = new Locale("en_UK");
ResourceBundle bundle =
ResourceBundle.getBundle("com.sarf.main.resources.bundle", local);
Parent rootPane =
FXMLLoader.load(getClass().getResource("fxml/home_icons.fxml"), bundle);
Scene scene = new Scene(rootPane);
primaryStage.setTitle("SARF");
primaryStage.setScene(scene);
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}
the resources file is simple. I am just at the beginning of the project. but i faced this porblem. anyway the resources file for now includes one entry:
grocery= Market
when I run the code, the label text is shown like : "%grocery", % sign is interpreted as plain text and the value is not shown as it is in the bundle.properties file.
any help?