MRM*_*MRM 2 java swing jspinner
我有2个组合框和一个微调器,其工作方式如下:如果第一个组合的所选项目发生了更改,则第二个组合会保留其选定的项目但重新调用微调器(微调器仅链接到第二个框).我的问题是,当我这样做时,我无法触发微调器的stateChange监听器.
这是强制第二个盒子在第一个盒子改变时重新选择它的最后一个项目的代码(这里没有错,它工作得很好):
String orientare = (String) orientareComboBox.getSelectedItem();
orientareComboBox.setSelectedItem(orientare);
Run Code Online (Sandbox Code Playgroud)
这是第二个框actionListener的代码:
public void actionPerformed(ActionEvent e) {
JComboBox combo = (JComboBox) e.getSource();
String value = combo.getSelectedItem().toString();
if (value.equalsIgnoreCase("oblica"))
{
unghiSpinner.setEnabled(true);
double unghi = (double) unghiSpinner.getValue();
unghiSpinner.setValue(new Double(unghi));
}
}
Run Code Online (Sandbox Code Playgroud)
锭床工人的听众:
public void stateChanged(ChangeEvent e)
{
if (unghiSpinner.isEnabled())
{
// do something
}
}
Run Code Online (Sandbox Code Playgroud)
我不知道我应该用什么命令unghiSpinner来触发它的监听器,因为setValue()不能这样做.