Facebook
From Insensitive Pelican, 3 Years ago, written in Java.
Embed
Download Paste or View Raw
Hits: 67
  1. package LMS.JavaFx;
  2.  
  3. import javafx.application.Application;
  4.  
  5. import javafx.geometry.Insets;
  6.  
  7. import javafx.scene.Group;
  8. import javafx.scene.Scene;
  9. import javafx.scene.control.*;
  10. import javafx.scene.layout.GridPane;
  11. import javafx.stage.Stage;
  12.  
  13. import java.io.IOException;
  14.  
  15. import java.util.ArrayList;
  16. import java.util.Arrays;
  17. import java.util.Map;
  18. import java.util.Properties;
  19. import java.util.TreeMap;
  20.  
  21. /*how to position combo box javafx*/
  22. public class ComboBoxSample extends Application {
  23.  
  24.     final Map<String, String[]> map = new TreeMap<>();
  25.  
  26.     private void fillMap() {
  27.         Properties prop = new Properties();
  28.         try {
  29.             prop.load(this.getClass().getResourceAsStream("C://Users/Emir/OneDrive/Documents/NewOne/LibraryManagementSystem/src/main/resources/companyProperty.properties"));
  30.             TreeMap<String, String[]> map = new TreeMap<>();
  31.             prop.forEach((key, value) -> map.put(key.toString(), value.toString().split(",")));
  32.             map.forEach((k, v) -> System.out.println(k + ": " + Arrays.toString(v)));
  33.  
  34.         } catch (IOException e) {
  35.             e.printStackTrace();
  36.         }
  37.     }
  38.  
  39.     public static void main(String[] args) {
  40.         launch(args);
  41.     }
  42.  
  43.     @Override
  44.     public void start(Stage stage) {
  45.         stage.setTitle("ComboBoxSample");
  46.         Scene scene = new Scene(new Group());
  47.  
  48.         final ComboBox<String> company = new ComboBox<>();
  49.         company.getItems().addAll(new ArrayList<>(map.keySet()));
  50.  
  51.         final ComboBox<String> priorityComboBox = new ComboBox<>();
  52.         priorityComboBox.getItems().addAll(new ArrayList<>(map.keySet()));
  53.  
  54.         company.setCellFactory(lv -> new ListCell<>() {
  55.             public void updateItem(String item, boolean empty) {
  56.                 super.updateItem(item, empty);
  57.                 if (empty) {
  58.                     setText(null);
  59.                 } else {
  60.                     setText(item);
  61.                     switch (item) {
  62.                         case "Automotive":
  63.                         case "Engineering, various":
  64.                         case "Electronics":
  65.                         case "Pharmaceuticals":
  66.                         case "Aerospace & Defense":
  67.                         case "Chemicals":
  68.                         case "Food & Beverages":
  69.                         case "Steel":
  70.                             setOpacity(0.5);
  71.                             setDisable(true);
  72.                             break;
  73.                         default:
  74.                             setOpacity(2);
  75.                             setDisable(false);
  76.                     }
  77.                 }
  78.             }
  79.         });
  80.  
  81.         company.valueProperty().addListener((ov, t, t1) -> {
  82.             char firstIDLetter = t1.toUpperCase().charAt(0);
  83.             char secondIDLetter = t1.toUpperCase().charAt(t1.length() - 1);
  84.             /* System.out.println(ov);*/
  85.             /*System.out.println(t); Previous value */
  86.             System.out.printf("%s%s", firstIDLetter, secondIDLetter);
  87.         });
  88.         priorityComboBox.setValue("Normal");
  89.         company.setValue("Hydrotec Military Vehicles");
  90.         GridPane grid = new GridPane();
  91.         grid.setVgap(4);
  92.         grid.setHgap(10);
  93.         grid.setPadding(new Insets(5, 5, 5, 5));
  94.         grid.add(new Label("Companies: "), 0, 0);
  95.         grid.add(company, 1, 0);
  96.         grid.add(new Label("Products: "), 0, 1);
  97.         grid.add(priorityComboBox, 1, 1);
  98.         /*grid.add(new Label("Subject: "), 0, 1);
  99.         grid.add(subject, 1, 1, 3, 1);*/
  100.         /* grid.add(text, 0, 2, 4, 1);*/
  101.         /* grid.add(button, 0, 3);*/
  102.         grid.setVgap(15);
  103.         /*grid.add(notification, 1, 3, 3, 1);*/
  104.  
  105.         Group root = (Group) scene.getRoot();
  106.         root.getChildren().add(grid);
  107.         stage.setScene(scene);
  108.         stage.show();
  109.  
  110.     }
  111. }
  112.  
  113.  
  114.  
  115.  
  116. package LMS.prop;
  117.  
  118. import LMS.JavaFx.ComboBoxSample;
  119.  
  120. import java.io.FileInputStream;
  121. import java.io.FileNotFoundException;
  122. import java.io.IOException;
  123. import java.io.InputStream;
  124. import java.util.Arrays;
  125. import java.util.LinkedHashMap;
  126. import java.util.Properties;
  127. import java.util.TreeMap;
  128.  
  129. public class Comp1 {
  130.     public static void main(String[] args) {
  131.  
  132.         try (InputStream input = new FileInputStream("C://Users/Emir/OneDrive/Documents/NewOne/LibraryManagementSystem/src/main/resources/companyProperty")) {
  133.  
  134.             Properties prop = new Properties();
  135.  
  136.             // load a properties file
  137.             prop.load(input);
  138.  
  139.             // get the property value and print it out
  140.             TreeMap<String, String[]> map = new TreeMap<>();
  141.             prop.forEach((key, value) -> map.put(key.toString(), value.toString().split(",")));
  142.             map.forEach((k, v) -> System.out.println(k + ": " + Arrays.toString(v)));
  143.         } catch (IOException exception) {
  144.             exception.printStackTrace();
  145.         }
  146.     }
  147. }
  148.  
  149.  
  150.  
  151.  
  152.  

Replies to Untitled rss

Title Name Language When
Re: Untitled Gracious Bat java 3 Years ago.