Facebook
From Gracious Bat, 3 Years ago, written in Java.
This paste is a reply to Untitled from Insensitive Pelican - view diff
Embed
Download Paste or View Raw
Hits: 82
  1.  final Map<String, String[]> map = new TreeMap<>();
  2.  
  3.     private void fillMap() {
  4.         Properties prop = new Properties();
  5.         this.getClass().getResourceAsStream("C:/Users/Emir/OneDrive/Documents/NewOne/LibraryManagementSystem/src/main/java/companyProperty");
  6.         prop.forEach((key, value) -> map.put(key.toString(), value.toString().split(",")));
  7.         map.forEach((k, v) -> System.out.println(k + ": " + Arrays.toString(v)));
  8.     }
  9.  
  10.     public static void main(String[] args) {
  11.         launch(args);
  12.     }
  13.  
  14.     @Override
  15.     public void start(Stage stage) {
  16.         fillMap();
  17.  
  18.         stage.setTitle("ComboBoxSample");
  19.         Scene scene = new Scene(new Group());
  20.         final ComboBox<String> company = new ComboBox<>();
  21.         company.getItems().addAll(new ArrayList<>(map.keySet()));
  22.  
  23.         final ComboBox<String> priorityComboBox = new ComboBox<>();
  24.         priorityComboBox.getItems().addAll(new ArrayList<>(map.keySet()));
  25.  
  26.         /*company.setCellFactory(lv -> new ListCell<>() {
  27.             public void updateItem(String item, boolean empty) {
  28.                 super.updateItem(item, empty);
  29.                 if (empty) {
  30.                     setText(null);
  31.                 } else {
  32.                     setText(item);
  33.                     switch (item) {
  34.                         case "Automotive":
  35.                         case "Engineering, various":
  36.                         case "Electronics":
  37.                         case "Pharmaceuticals":
  38.                         case "Aerospace & Defense":
  39.                         case "Chemicals":
  40.                         case "Food & Beverages":
  41.                         case "Steel":
  42.                             setOpacity(0.5);
  43.                             setDisable(true);
  44.                             break;
  45.                         default:
  46.                             setOpacity(2);
  47.                             setDisable(false);
  48.                     }
  49.                 }
  50.             }
  51.         });
  52.  
  53.         company.valueProperty().addListener((ov, t, t1) -> {
  54.             char firstIDLetter = t1.toUpperCase().charAt(0);
  55.             char secondIDLetter = t1.toUpperCase().charAt(t1.length() - 1);
  56.             *//* System.out.println(ov);*//*
  57.             *//*System.out.println(t); Previous value *//*
  58.             System.out.printf("%s%s", firstIDLetter, secondIDLetter);
  59.         });*/
  60.         priorityComboBox.setValue("Normal");
  61.         company.setValue("Hydrotec Military Vehicles");
  62.         GridPane grid = new GridPane();
  63.         grid.setVgap(4);
  64.         grid.setHgap(10);
  65.         grid.setPadding(new Insets(5, 5, 5, 5));
  66.         grid.add(new Label("Companies: "), 0, 0);
  67.         grid.add(company, 1, 0);
  68.         grid.add(new Label("Products: "), 0, 1);
  69.         grid.add(priorityComboBox, 1, 1);
  70.         /*grid.add(new Label("Subject: "), 0, 1);
  71.         grid.add(subject, 1, 1, 3, 1);*/
  72.         /* grid.add(text, 0, 2, 4, 1);*/
  73.         /* grid.add(button, 0, 3);*/
  74.         grid.setVgap(15);
  75.         /*grid.add(notification, 1, 3, 3, 1);*/
  76.  
  77.         Group root = (Group) scene.getRoot();
  78.         root.getChildren().add(grid);
  79.         stage.setScene(scene);
  80.         stage.show();
  81.  
  82.     }
  83. }
  84.  
  85.  
  86.  
  87.  
  88.  
  89.  
  90.  
  91.