package LMS.JavaFx; import javafx.application.Application; import javafx.geometry.Insets; import javafx.scene.Group; import javafx.scene.Scene; import javafx.scene.control.*; import javafx.scene.layout.GridPane; import javafx.stage.Stage; import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; import java.util.Map; import java.util.Properties; import java.util.TreeMap; /*how to position combo box javafx*/ public class ComboBoxSample extends Application { final Map map = new TreeMap<>(); private void fillMap() { Properties prop = new Properties(); try { prop.load(this.getClass().getResourceAsStream("C://Users/Emir/OneDrive/Documents/NewOne/LibraryManagementSystem/src/main/resources/companyProperty.properties")); TreeMap map = new TreeMap<>(); prop.forEach((key, value) -> map.put(key.toString(), value.toString().split(","))); map.forEach((k, v) -> System.out.println(k + ": " + Arrays.toString(v))); } catch (IOException e) { e.printStackTrace(); } } public static void main(String[] args) { launch(args); } @Override public void start(Stage stage) { stage.setTitle("ComboBoxSample"); Scene scene = new Scene(new Group()); final ComboBox company = new ComboBox<>(); company.getItems().addAll(new ArrayList<>(map.keySet())); final ComboBox priorityComboBox = new ComboBox<>(); priorityComboBox.getItems().addAll(new ArrayList<>(map.keySet())); company.setCellFactory(lv -> new ListCell<>() { public void updateItem(String item, boolean empty) { super.updateItem(item, empty); if (empty) { setText(null); } else { setText(item); switch (item) { case "Automotive": case "Engineering, various": case "Electronics": case "Pharmaceuticals": case "Aerospace & Defense": case "Chemicals": case "Food & Beverages": case "Steel": setOpacity(0.5); setDisable(true); break; default: setOpacity(2); setDisable(false); } } } }); company.valueProperty().addListener((ov, t, t1) -> { char firstIDLetter = t1.toUpperCase().charAt(0); char secondIDLetter = t1.toUpperCase().charAt(t1.length() - 1); /* System.out.println(ov);*/ /*System.out.println(t); Previous value */ System.out.printf("%s%s", firstIDLetter, secondIDLetter); }); priorityComboBox.setValue("Normal"); company.setValue("Hydrotec Military Vehicles"); GridPane grid = new GridPane(); grid.setVgap(4); grid.setHgap(10); grid.setPadding(new Insets(5, 5, 5, 5)); grid.add(new Label("Companies: "), 0, 0); grid.add(company, 1, 0); grid.add(new Label("Products: "), 0, 1); grid.add(priorityComboBox, 1, 1); /*grid.add(new Label("Subject: "), 0, 1); grid.add(subject, 1, 1, 3, 1);*/ /* grid.add(text, 0, 2, 4, 1);*/ /* grid.add(button, 0, 3);*/ grid.setVgap(15); /*grid.add(notification, 1, 3, 3, 1);*/ Group root = (Group) scene.getRoot(); root.getChildren().add(grid); stage.setScene(scene); stage.show(); } } package LMS.prop; import LMS.JavaFx.ComboBoxSample; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; import java.util.Arrays; import java.util.LinkedHashMap; import java.util.Properties; import java.util.TreeMap; public class Comp1 { public static void main(String[] args) { try (InputStream input = new FileInputStream("C://Users/Emir/OneDrive/Documents/NewOne/LibraryManagementSystem/src/main/resources/companyProperty")) { Properties prop = new Properties(); // load a properties file prop.load(input); // get the property value and print it out TreeMap map = new TreeMap<>(); prop.forEach((key, value) -> map.put(key.toString(), value.toString().split(","))); map.forEach((k, v) -> System.out.println(k + ": " + Arrays.toString(v))); } catch (IOException exception) { exception.printStackTrace(); } } }