Hello,
I’m trying to disable a button on certain conditions in one of my GUI.
At first I tried :
[java]
element = screen.findElementByName( “btnNewGame” );
element.disable()
[/java]
Problem :
My button is still intercepting Mouse focus.
So I tried :
[java]
element = screen.findElementByName( “btnNewGame” );
element.startEffect(EffectEventId.onCustom);
element.setFocusable( false );
element.setVisibleToMouseEvents( false );
[/java]
With a effect OnCutom :
[xml]
<onCustom name=“fade” start="#ff" end="#30" neverStopRendering=“true” />
[/xml]
It looks great but …
I still have a problem with focus :
My button “btnNewGame” has the focus by default. So when I call the method
[java]
element.setVisibleToMouseEvents( false );
[/java]
The button is still with the focused appearance and It doesn’t disappear.
I tried
[java]
//Give the focus to the End / Continue button
Element element = screen.findElementByName( “btnEnd” );
element.setFocus();
//Invalidate the new Game button
element = screen.findElementByName( “btnNewGame” );
element.startEffect(EffectEventId.onCustom);
element.setFocusable( false );
element.setVisibleToMouseEvents( false );
[/java]
But it the button “btnNewGame” remains with the focused appearance.
Do I need to delay the setVisibleToMouseEvents call ?
Thanks in advance.
you need to delay the use of this until nifty 1.3 is released
unfortunatly enable/disable support in nifty 1.2 is quite rudimental. there already exists a feature request (with patches by tumani!) for this in the feature tracker at sf.net https://sourceforge.net/tracker/?func=detail&aid=3035579&group_id=223898&atid=1059825.
so, you’ve done everything correct and the situation will improve with 1.3.
in the meantime you should be able to call removeFromFocusHandler() on the element to remove the focus.
1 Like
Ok, thanks!