0
如何將包含String項的JComboBox綁定到使用JGoodies的bean中的Integer值
我想在JComboBox名稱中顯示並將其綁定到該名稱的某個ID值。JGoodies JComboBox綁定
如何將包含String項的JComboBox綁定到使用JGoodies的bean中的Integer值
我想在JComboBox名稱中顯示並將其綁定到該名稱的某個ID值。JGoodies JComboBox綁定
使用MVP的架構,你將有演示SelectInList一個誰一直要列出對象的列表:例如:
class MyObject {
private Integer id;
private String name;
...
//getters and setters
}
class MyView {
private MyPresentationModel;
private JComboBox myComboBox;
...
private void buildComponents {
myComboBox = BasicComponentFactory.createComboBox(getPresentationModel().getMyObjectsSelectionInList(), new ListCellRenderer() {
protected DefaultListCellRenderer defaultRenderer = new DefaultListCellRenderer();
@Override
public Component getListCellRendererComponent(JList list, Object value,
int index, boolean isSelected, boolean cellHasFocus) {
JLabel renderer = (JLabel) defaultRenderer
.getListCellRendererComponent(list, value, index, isSelected,
cellHasFocus);
renderer.setText(((MyObject) value).getName()); //this is point
return renderer;
}
});
}
}
class MyPresentationModel extends com.jgoodies.binding.PresentationModel {
private SelectionInList myObjetcsSelectionInList;
private List<MyObject> list;
private MyModel myModel;
public MyPresentationModel(MyModel myModel) {
this.myModel = myModel;
list = //LOAD LIST
}
public SelectionInList getPeriodTypeSelectionInList() {
if (myObjetcsSelectionInList == null) {
myObjetcsSelectionInList = new SelectionInList(list.toArray(new MyObejct[list.size()]), getModel(MyModel.PROPERTY_MY_OBJECT));
myObjetcsSelectionInList.setSelectionIndex(0);
}
return myObjetcsSelectionInList;
}
...
}
class MyModel {
static public String PROPERTY_MY_OBJECT = "myObject";
private MyObject myObject;
// getters and setters
}
歡迎堆棧溢出!爲了得到積極的迴應,請顯示您已經嘗試過的內容。理想情況下,添加一個[最小,完整,測試,可讀示例](http://stackoverflow.com/help/mcve)。 –