Jump to content

JavaFX Displayed Within Game?


Jimmeh

Recommended Posts

Hi there. The past couple days I've been trying to add my own AbstractList object to my custom screen. It's been a real challenge to actually just get it to display right (of which, I still haven't managed to do). I thought I'd see if I could get JavaFX working within my project and glad to say I have. My question here is if it's possible to get the JavaFX scene to display within the game, rather than opening a separate window and pausing the game, like so (this is just a test Scene I grabbed from an old project):

https://gyazo.com/d24922903975e107fdf626899bb4aabf

If not, I'll give AbstractList another shot. Here's the relevant code:

@Mod("testmod")
public final class TestMod extends Application {
    private Stage stage;
  	
  public TestMod() {
        try {
            final Method JFXInit = JFXPanel.class.getDeclaredMethod("initFx");
            JFXInit.setAccessible(true);
            JFXInit.invoke(null);
        } catch (Exception e) {
            e.printStackTrace();
        }

        Platform.runLater(() -> {
            stage = new Stage();
        });
    }

    @Override
    public void start(Stage primaryStage) throws Exception {
        this.stage = primaryStage; //I don't believe this code is ever even reached/fired
    }

    public void display() {
        Platform.runLater(() -> {
            try {
                Scene login =  new Scene(FXMLLoader.load(getClass().getResource("/fxml/login.fxml")), 333, 316);
                this.stage.setScene(login);
                this.stage.show();
            } catch (IOException e) {
                e.printStackTrace();
            }
        });
    }

    

I'm using reflection to call the init() method because otherwise the ToolKit isn't be initialized for JavaFX (it was one of the most upvoted solutions on StackOverflow, so I went with it). Thanks for any help!

Edited by Jimmeh
Code Formatting
Link to comment
Share on other sites

  • Jimmeh changed the title to JavaFX Displayed Within Game?

Brainstorming an idea here, not sure if it'll work. Is it possible to use a Mixin to have the Minecraft class extend Application from JavaFX? My thinking behind this is so that the Minecraft instance itself contains the Stage in which I can display the Scenes, perhaps allowing them to be displayed without forcing the game to be paused by opening separate windows. I've never used Mixins, so I'm unsure if this is possible or if it's even a good idea.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.