Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draw FontIcon (Ikonli) directly on "javafx.scene.Canvas" #162

Open
tretonio opened this issue Feb 22, 2024 · 0 comments
Open

Draw FontIcon (Ikonli) directly on "javafx.scene.Canvas" #162

tretonio opened this issue Feb 22, 2024 · 0 comments

Comments

@tretonio
Copy link

tretonio commented Feb 22, 2024

How to draw FontIcon (Ikonli) directly inside "javafx.scene.Canvas" ?
Version 12.3.1

Thank's

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.SnapshotParameters;
import javafx.scene.canvas.Canvas;
import javafx.scene.canvas.GraphicsContext;
 
import javafx.scene.image.Image;
 
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.Pane;

import javafx.stage.Stage;

import org.kordamp.ikonli.fontawesome5.FontAwesomeSolid;
import org.kordamp.ikonli.javafx.FontIcon;
 

public class IkonliCanvas extends Application {
   
    
    
    @Override
    public void start(Stage primaryStage) {
        // Criar um Canvas
        Canvas canvas = new Canvas(100, 400 );
        GraphicsContext gc = canvas.getGraphicsContext2D();        
        
        Pane pcanvas = new Pane();
        pcanvas.getChildren().add(canvas); 
        
        FontIcon fi = new FontIcon(FontAwesomeSolid.APPLE_ALT);      
        fi.setIconSize(30);
    
        Image snapshot = fi.snapshot(new SnapshotParameters(), null);       
        gc.drawImage(snapshot, 40,100);
        
        
        Pane p = new Pane();
        p.getChildren().add(fi);
        p.setPrefWidth(100);        
        fi.setLayoutX(40);
        fi.setLayoutY(100); 
        
        BorderPane bp = new BorderPane();
        bp.setLeft(p);
        bp.setCenter(pcanvas);
             
        Scene scene = new Scene(bp, 220,400);
    
        primaryStage.setScene(scene);
        primaryStage.setTitle("Canvas Ikonli");
        primaryStage.show();
    }
 
    public static void main(String[] args) {
        launch(args);
    }
    
}

@tretonio tretonio changed the title How to draw inside the Canvas JavaFX Draw FontIcon (Ikonli) directly on "javafx.scene.Canvas" Feb 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant