所以,我想根据从对象中读取的值来更改comboBox
的选定值。这就是我到目前为止所做的:
public String[] waluta=new String[] {"EUR","PLN","USD"};
public GameEditFrame(int index) {
...
JComboBox walutaBox = new JComboBox(waluta);
String tmp=main.katalog.gra.get(index).cena.getWaluta();
if (tmp=="EUR" || tmp==null){
walutaBox.setSelectedItem(waluta[0]);
}else if (tmp=="PLN"){
walutaBox.setSelectedItem(waluta[1]);
}else if (tmp=="USD"){
walutaBox.setSelectedItem(waluta[2]);
}
...
}
可悲的是,这不起作用。有什么想法吗?
编辑:已解决
感谢ZouZou和MadProgrammer的评论,我修改了以前的代码。现在它看起来像这样,它工作正常:
public String[] waluta=new String[] {"EUR","PLN","USD"};
public GameEditFrame(int index) {
...
JComboBox walutaBox = new JComboBox(waluta);
String tmp=main.katalog.gra.get(index).cena.getWaluta();
if (tmp==null)
tmp="EUR";
walutaBox.setSelectedItem(tmp);
...
}