Javafx changing java icon on stage or replacing it with your own icon.
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.image.Image;
import javafx.stage.Stage;
import javafx.scene.layout.StackPane;
public class StageIcon extends Application
{
public static void main(String[]args)
{
Application.launch(args);
}
@Override
public void start(Stage primaryStage)
{
StackPane root = new StackPane();
Scene scene = new Scene(root,600,400);
//icon for primarystage
Image twitterIcon = new Image(getClass().getResourceAsStream("twitter.png"));//twitter like icon
primaryStage.getIcons().add(twitterIcon);//adding icon to primaryStage,changing from default java icon to twitterIcon.
primaryStage.setScene(scene);
primaryStage.setTitle("Primary Stage Iconified");
primaryStage.show();
}
}
The code above gives the result below:
Comments
Post a Comment