Monday, February 25, 2013

Get installed font families using Font.getFamilies()

Get installed font families using Font.getFamilies()
Get installed font families using Font.getFamilies()


package javafxfonts;

import java.util.List;
import javafx.application.Application;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.scene.Scene;
import javafx.scene.control.ListView;
import javafx.scene.layout.StackPane;
import javafx.scene.text.Font;
import javafx.stage.Stage;

/**
 *
 * @web http://java-buddy.blogspot.com/
 */
public class JavaFXFonts extends Application {
    
    @Override
    public void start(Stage primaryStage) {
        primaryStage.setTitle("http://java-buddy.blogspot.com/");
        
        ListView<String> listView = new ListView<>();
        List<String> familiesList = Font.getFamilies();
        ObservableList<String> familiesObservableList = 
                FXCollections.observableArrayList(familiesList);
        listView.setItems(familiesObservableList);
        
        StackPane root = new StackPane();
        root.getChildren().add(listView);
        primaryStage.setScene(new Scene(root, 300, 250));
        primaryStage.show();
    
    }

    public static void main(String[] args) {
        launch(args);
    }
}


more: Example to apply font.

No comments:

Post a Comment

Post a Comment