Skip to main content

Component with HUD

4 replies [Last post]
morrisford
Offline
Joined: 2008-03-17

I am working on adding a HUD to a component. I created a simple JPanel with a couple of simple items. Then I created a menu item successfully with the action listener creating the HUD. This is the code in the action listener:

<br />
                            HUD mainHUD = HUDManagerFactory.getHUDManager().getHUD("main");<br />
                            EditorHUD panel = new EditorHUD();<br />
                            hudComponent = mainHUD.createComponent(panel);<br />
                            hudComponent.setName("ScriptEditore");<br />
                            hudComponent.setPreferredLocation(Layout.NORTH);<br />
                            hudComponent.setVisible(true);<br />
                            mainHUD.addComponent(hudComponent);<br />
                            mainHUD.setVisible(true);<br />

All i get is a client screen blink. I assume the HUD item is getting created but immediately disappearing.

Help??

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
jagwire
Offline
Joined: 2008-06-21

Morrisford,

Depending on which thread you're calling that code from you might need to put it on the Awt Event queue as follows:

[code]
SwingUtilities.invokeLater(new Runnable() {
public void run() {
...
}
});
[/code]

That being said, you might try setting the hudcomponent's visibility after it's added to the mainHUD. Depending on where this code is being invoked, you probably don't need to set the mainHUD to visible either.

Best Regards,
jW

morrisford
Offline
Joined: 2008-03-17

I am calling that code in the action listener for the menu item. Does that mean that I need to do the invokeLater?

jagwire
Offline
Joined: 2008-06-21

If you're not getting NPE's, most likely it doesn't need to be. If you find that you start to, it wouldn't hurt to call invokeLater.

morrisford
Offline
Joined: 2008-03-17

Thanks for your help. It is displaying now. I added the invokeLater and changed the set visible things. The action listener for the menu item looks like this now.

[code]
public void actionPerformed(ActionEvent e)
{
// Depending upon whether the checkbox is selected or not,
// either hide or show the HUD Component and turn on/off the
// camera taking the snapshots for the map.
SwingUtilities.invokeLater(new Runnable()
{
public void run()
{
System.out.println("____________________ in menu select");
HUD mainHUD = HUDManagerFactory.getHUDManager().getHUD("main");
EditorHUD panel = new EditorHUD();
hudComponent = mainHUD.createComponent(panel);
hudComponent.setName("ScriptEditore");
hudComponent.setPreferredLocation(Layout.NORTH);
mainHUD.addComponent(hudComponent);
hudComponent.setVisible(true);
// mainHUD.setVisible(true);
}
});
}
});
JmeClientMain.getFrame().addToToolsMenu(editScripts, -1);
[/code]