/**
* Adds an input field to select from a ComboBox
* @param text text to be shown on a label
* @param property property to be changed in Defaults
* @param cont container where input field must be added
* @param values Map with internal value <-> showed value relations
*/
protected void addInputCombo(String text, final String property, Container cont, final Map<String, String> values) {
JLabel label = new JLabel(text + ":");
JComboBox combo = new JComboBox(values.values().toArray());
combo.setName(property);
label.setLabelFor(combo);
combo.setSelectedItem(values.get(Defaults.get(property)));
// Sets maximum size to minimal one, otherwise springLayout will stretch this
combo.setMaximumSize(new Dimension(combo.getMaximumSize().width, combo.getMinimumSize().height));
combo.addItemListener(new ItemListener() {
public void itemStateChanged(ItemEvent e) {
// As Map does not allows reverse mapping, scans the entire keyset to
// find the key corresponding to a given object
Object[] keys = values.keySet().toArray();
for (Object key : keys) {
if (values.get(key) == e.getItem()) {
Defaults.set(property, (String) key);
}
}
}
});
cont.add(label);
cont.add(combo);
}
DefaultsEditor.java 文件源码
java
阅读 44
收藏 0
点赞 0
评论 0
项目:jmt
作者:
评论列表
文章目录