Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Main extends Application {
- @Override
- public void start(Stage primaryStage) {
- primaryStage.setTitle("Choose Symbol");
- StackPane sp2 = new StackPane();
- final Label label = new Label();
- sp2.getChildren().add(label);
- final ListView<String> listView = new ListView<>();
- collectFonts(listView);
- listView.setOnMouseClicked(new EventHandler<MouseEvent>() {
- @Override
- public void handle(MouseEvent t) {
- String selectedFamily = listView.getSelectionModel().getSelectedItem();
- // Apply the selected font family
- Font selectedFont = Font.font(selectedFamily, 20.0);
- label.setText(selectedFamily);
- label.setFont(selectedFont);
- }
- });
- SplitPane splitPane = new SplitPane();
- StackPane sp1 = new StackPane();
- sp1.getChildren().add(listView);
- splitPane.getItems().addAll(sp1, sp2);
- primaryStage.setScene(new Scene(splitPane, 500, 350));
- primaryStage.show();
- }
- /**
- * @param listView
- */
- private void collectFonts(final ListView<String> listView) {
- List<String> familiesList = Font.getFamilies();
- List<String> list = new ArrayList<String>();
- ObservableList<String> familiesObservableList = FXCollections.observableList(list);
- for (String fontString : familiesList) {
- if ((fontString.startsWith("Map") && fontString.contains("Unicode"))) {
- familiesObservableList.add(fontString);
- // System.out.print(fontString);
- }
- }
- listView.setItems(familiesObservableList);
- }
- public static void main(String[] args) {
- launch(args);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement