Swing in Jmonkey for dialogs

Hello, i’ writing a program with JME to construct HVAC-components for the industry.


I’m using nifty for the interaction with the user. But it’s a lot of work to make a dialog.
Is there a possibility to generate dialogs in a wysiwyg-way? Can i use swing to creat dialogs. It ist not nessesary that the dialog runs in the same window as the graphics and the graphics can be paused while the dialog is displayed.

1 Like

you can use jdialogs in jme.
just try adding something like this

JDialog dialog = new JDialog();
dialog.setSize(640, 480);
JButton button = new JButton(“test”);
dialog.add(button);
dialog.setVisible(true);

don’t know about wysiwyg.
You can also add a jmecanvas into swing.

Create a JPanel that has your GUI components , & attach the JPanel to a JOptionPane#showMessageDialog() like :

JPanel panel = new JPanel();
 panel.add(new JButton("Click"));
 panel.add(new JTextField(20));
 panel.add(new JLabel("Label"));
 JOptionPane.showMessageDialog((JComponent)jme.getCanvas(),panel,"Information",JOptionPane.INFORMATION_MESSAGE);

but it will pause the game (lose focus).

for more info :

I would recommend using javafx in jme. You can use the jfx SceneBuilder and it makes developing UIs very quick.

There are a couple forks floating around for it: tlf30/jme-jfx-11: A JavaFX 11 bridge to create a 2D GUI in jMonkeyEngine (github.com)

I am working on an update for it that corrects some issues (actually, I thought I had pushed it somewhere but am not finding the repo…) But none of those issues should impact you.

1 Like

I have a project that uses lemur but I added a just few Swing dialog windows (open file, color picker and confirmation) and the problem is that I cannot upgrade to lwjgl3.
As soon as I try to open a dialog the application crashes, so I’m suck with lwjgl2 (and consequently java8) until I re implement those dialogs with lemur.
So my advise is avoid Swing, maybe give Lemur a try instead of Nifty.

Note that Lemur already has a simple (really simple) color chooser control… and definitely already has built in confirmation dialogs.

1 Like

Thanks for letting me know. I remember seeing the color picker in some screenshot and it seemed good enough for my use case.