本文整理汇总了Java中javax.swing.JComboBox.setName方法的典型用法代码示例。如果您正苦于以下问题:Java JComboBox.setName方法的具体用法?Java JComboBox.setName怎么用?Java JComboBox.setName使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.swing.JComboBox
的用法示例。
在下文中一共展示了JComboBox.setName方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: addInputCombo
import javax.swing.JComboBox; //导入方法依赖的package包/类
/**
* 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);
}
示例2: addBooleanComboBox
import javax.swing.JComboBox; //导入方法依赖的package包/类
/**
* Adds a ComboBox to select a boolean property
* @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
*/
protected void addBooleanComboBox(String text, final String property, Container cont) {
JLabel label = new JLabel(text + ":");
JComboBox combo = new JComboBox(new Object[] { Boolean.TRUE.toString(), Boolean.FALSE.toString() });
combo.setName(property);
label.setLabelFor(combo);
combo.setSelectedItem(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) {
Defaults.set(property, (String) e.getItem());
}
});
cont.add(label);
cont.add(combo);
}