There is a way by using two different stages but it may have it's problems (only tested on Windows 7). The following example uses Java 8/JavaFX 8.
This code sets the icon that is shown on the taskbar on the primary stage received on JavaFX startup but makes the stage invisible (transparent, zero size). It then opens a new and visible window with a different icon.
Since this is only a child window and not the real one, the hide event has to be delegated to the hidden stage to close the application. There may be more events that have to be delegated like minimizing the window.
public class Main extends Application {
public static void main(String[] args) {
Application.launch(args);
}
@Override
public void start(Stage primaryStage) throws Exception {
primaryStage.getIcons().add(getImage("taskbar_icon.png"));
primaryStage.initStyle(StageStyle.TRANSPARENT);
primaryStage.setWidth(0);
primaryStage.setHeight(0);
primaryStage.show();
Stage visibleStage = new Stage();
visibleStage.initOwner(primaryStage);
visibleStage.getIcons().add(getImage("window_icon.png"));
visibleStage.setScene(new Scene(...));
visibleStage.setOnHidden(e -> Platform.runLater(primaryStage::hide));
visibleStage.show();
}
}