Advertisement
Guest User

Untitled

a guest
Aug 30th, 2016
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.60 KB | None | 0 0
  1. public class Main extends Application {
  2. @Override
  3. public void start(Stage primaryStage) {
  4. primaryStage.setTitle("Choose Symbol");
  5.  
  6. StackPane sp2 = new StackPane();
  7. final Label label = new Label();
  8. sp2.getChildren().add(label);
  9.  
  10. final ListView<String> listView = new ListView<>();
  11. collectFonts(listView);
  12.  
  13. listView.setOnMouseClicked(new EventHandler<MouseEvent>() {
  14.  
  15. @Override
  16. public void handle(MouseEvent t) {
  17. String selectedFamily = listView.getSelectionModel().getSelectedItem();
  18.  
  19. // Apply the selected font family
  20. Font selectedFont = Font.font(selectedFamily, 20.0);
  21. label.setText(selectedFamily);
  22. label.setFont(selectedFont);
  23. }
  24. });
  25.  
  26. SplitPane splitPane = new SplitPane();
  27. StackPane sp1 = new StackPane();
  28. sp1.getChildren().add(listView);
  29.  
  30. splitPane.getItems().addAll(sp1, sp2);
  31.  
  32. primaryStage.setScene(new Scene(splitPane, 500, 350));
  33. primaryStage.show();
  34. }
  35.  
  36. /**
  37. * @param listView
  38. */
  39. private void collectFonts(final ListView<String> listView) {
  40. List<String> familiesList = Font.getFamilies();
  41.  
  42. List<String> list = new ArrayList<String>();
  43. ObservableList<String> familiesObservableList = FXCollections.observableList(list);
  44.  
  45. for (String fontString : familiesList) {
  46. if ((fontString.startsWith("Map") && fontString.contains("Unicode"))) {
  47. familiesObservableList.add(fontString);
  48. // System.out.print(fontString);
  49. }
  50. }
  51. listView.setItems(familiesObservableList);
  52. }
  53.  
  54. public static void main(String[] args) {
  55. launch(args);
  56. }
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement