Some problems with swing components when using several JMEDesktopStates


I’m having some problems when using several JMEDesktopStates in a StandardGame.

I’m trying to divide some swing components (like JMenuBars, Buttons, Panels or JInternalFrames) in different JMEDesktopStates in order to make some Show/Hide effects individually.

I will use a simple scenario to show the problems I’m having:

I have a JMenuBar with a typical File menu and a Exit item in a JMEDesktopState and a button in other JMEDesktopState.The button has a char ‘h’ set as mnemonic.

Here’s the code:

public static void main(String[] args) throws Exception
      UIManager.setLookAndFeel( UIManager.getSystemLookAndFeelClassName() );      
      //jmecsGame.DISPLAY_MODE = jmecsGame.DISPLAY_CANVAS; - not yet possible
      StandardGame game = new StandardGame("A Simple Test");

      // 3D Stuff
      DebugGameState mainScene = new DebugGameState(); mainScene.setActive(true);

      // Game StateNodes and scenegraph
      final GameStateNode<JMEDesktopState> hud = new GameStateNode<JMEDesktopState>("hud"); hud.setActive(true);      
      final GameStateNode<DebugGameState> scene = new GameStateNode<DebugGameState>("scene"); scene.setActive(true);         
      final JMEDesktopState menuBarLayer = new JMEDesktopState(); menuBarLayer.setActive(true);
      final JMEDesktopState desktopLayer = new JMEDesktopState();   desktopLayer.setActive(true);         
      // Swing stuff
      final JButton hideDesktopButton = new JButton("Hide/Show");
      hideDesktopButton.addActionListener(new ActionListener()
         public void actionPerformed(ActionEvent e) {
      final JMenuBar menuBar = new JMenuBar();
      JMenu fileMenu = new JMenu("File");
      JMenuItem exitItem = new JMenuItem("Exit");
      // Adding things to the scene
      GameTaskQueueManager.getManager().update(new Callable<Object>() {
         public Object call() throws Exception
            menuBar.setLocation(0, 0);
            return null;

The problems are:
1) The mnemonics have some strange behavior. Only the MenuBar mnemonics seems to respond. (The keybinds of the scene debugstate are ok)
2) The Exit Item only shows down when using the mnemonics...if I use the mouse the menu dont respond. (If I take the button state off the game it will work perfectly)

- Its ok to have several desktopstates in a single standardgame? The problems that I'm facing is because I'm forgetting something? (sorry, I'm new to jme)
- Can you give me some guidance how to make a good management of keybindings and Inputhandlers and Mnemonics in a standardgane when using several gamastates?

I'm sorry if my jme approach isn't good...I'm exploring jme while testing it and I'm far away to have the big picture for the standardgame...but I like the concept..a lot! Please guide me ...

Thanks for any help.


Hi,  :smiley:

Has a beginner I'm facing "the common" indecision about which GUI Library to choose.

I considered the most popular ones and made my own tests (swing in jmedesktop(states), BUI and FengGui). I know that most of you guys don't use/prefer swing but I decided to give less importance to hud (I shouldn't spend much time on hud developing) since I'm not developing a game but a simulation platform and its not so bad to have the typical swing "appearance", neither the application is to heavy for considering swing garbage or other swing disadvantages.

But I still have a problem…the world its not perfect and I can't have the best of all in one single library! I'll need some important features in the GUI such as:

  • As I posted first in this topic, "pacific" mouse/keyboard event handling and integration
  • I will massively use trees and need a simple and intuitive tree management
  • I would like to implement the pinpoint button in the GUI InternalFrames in order to minimize all HUD elements except the ones that are pinpointed = costumize some parts of the gui

    So, I know I cant get all of these (very) important features in my GUI when choosing only one GUI Library but, can you give some directions in which I can choose to better fit this tasks or if I'm doing a really great mistake by choosing swing?

    Thanks for any help,