我想创建获取单选按钮的方法,并在标记其他单选按钮时将其标记为。这是我漂亮的gui示例菜单:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<nifty>
<useControls filename="nifty-default-controls.xml"/>
<useStyles filename="nifty-default-styles.xml"/>
<screen id="ustawieniaWyswietlania" controller="PakietyPodstawowe.Kontroler.KontrolerUstawieńWyświetlania">
<layer id="GLayer0" childLayout="center">
<control id="r1" name="radioButtonGroup"/>
<panel id="GPanel0" childLayout="absolute" width="100%" x="210" y="257" style="nifty-panel-simple" height="100%">
<control name="radioButton" id="GRadioButton0" group="r1" x="193" y="236"/>
<control name="radioButton" id="GRadioButton1" group="r1" x="327" y="244"/>
</panel>
</layer>
</screen>
</nifty>
我的方法:
@NiftyEventSubscriber(pattern="GRadioButton.*")
public void setSelected(final String id, final RadioButtonStateChangedEvent event) {
IO.drukujL(event.getRadioButton().getElement().getId());
Element element = screen.findElementByName("GRadioButton1");
// element.setMarkted(); this method I can't find
}
也许这个问题很简单,但我不知道在标记GRadioButton0时如何自动标记GRadioButton1。
答案 0 :(得分:1)
您需要使用其他方法来访问RadioButton控件API。
使用类似:
RadioButton radioButton = screen.findNiftyControl("GRadioButton1", RadioButton.class);
radioButton.select();
您可能需要阅读Nifty GUI PDF Manual中的“11个控件”一章。维基中有一个Radiobutton reference,而RadioButton JavaDoc也可以提供帮助。
请注意,wiki是针对1.3.x编写的,但大部分信息仍应对1.4.x有效