I am trying to get the simple radio button example to work and I can’t get the onRadioGroup1Changed method to fire. here is my code:
public class Main extends SimpleApplication implements ScreenController {
public Nifty nifty;
public static void main(String[] args) {
Main app = new Main();
app.setDisplayStatView(false);
app.setShowSettings(false);
AppSettings settings = new AppSettings(true);
settings.setFullscreen(false);
settings.setResolution(1280, 720);
settings.setFrameRate(60);
app.setSettings(settings);
app.start();
}
@Override
public void simpleInitApp() {
setupGui();
}
@Override
public void simpleUpdate(float tpf) {
}
@Override
public void simpleRender(RenderManager rm) {
}
private void setupGui() {
getFlyByCamera().setEnabled(false);
NiftyJmeDisplay niftyDisplay = new NiftyJmeDisplay(assetManager,
inputManager,
audioRenderer,
guiViewPort);
nifty = niftyDisplay.getNifty();
nifty.fromXml("Interface/newradiobutton.xml", "start", this);
guiViewPort.addProcessor(niftyDisplay);
inputManager.setCursorVisible(true);
}
@NiftyEventSubscriber(id="RadioGroup-1")
public void onRadioGroup1Changed(final String id, final RadioButtonGroupStateChangedEvent event) {
System.out.println("RadioButton [" + event.getSelectedId() + "] is now selected. The old selection was [" + event.getPreviousSelectedId() + "]");
}
@Override
public void bind(Nifty nifty, Screen screen) { }
@Override
public void onStartScreen() { }
@Override
public void onEndScreen() { }
}
And here is my corresponding xml file.
<?xml version="1.0" encoding="UTF-8"?>
<nifty xmlns="http://nifty-gui.sourceforge.net/nifty-1.3.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://nifty-gui.sourceforge.net/nifty-1.3.xsd http://nifty-gui.sourceforge.net/nifty-1.3.xsd">
<useStyles filename="nifty-default-styles.xml" />
<useControls filename="nifty-default-controls.xml" />
<screen id="start">
<layer childLayout="center">
<panel childLayout="horizontal" align="center" valign="center" width="50%" height="50%" backgroundColor="#55a5" padding="10">
<control id="RadioGroup-1" name="radioButtonGroup" />
<control name="label" text="Radio Buttons" />
<panel width="10" />
<panel childLayout="vertical" backgroundColor="#8001" paddingLeft="7px" paddingRight="7px" paddingTop="4px" paddingBottom="4px" width="105px">
<effect>
<onActive name="border" color="#0008" />
</effect>
<panel childLayout="horizontal">
<control name="label" text="Option 1" with="60px" />
<control name="radioButton" id="option-1" group="RadioGroup-1" />
</panel>
<panel childLayout="horizontal">
<control name="label" text="Option 2" with="60px" />
<control name="radioButton" id="option-2" group="RadioGroup-1" />
</panel>
<panel childLayout="horizontal">
<control name="label" text="Option 3" with="60px" />
<control name="radioButton" id="option-3" group="RadioGroup-1" />
</panel>
<panel childLayout="horizontal">
<control name="label" text="Option 4" with="60px" />
<control name="radioButton" id="option-4" group="RadioGroup-1" />
</panel>
</panel>
</panel>
</layer>
</screen>
</nifty>
I can’t see how I am doing anything different from the example and yet I can’t get the corresponding method to fire when I change radio buttons. The radio buttons change color when I click them, but the method doesn’t work. Any ideas?