本文整理匯總了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);
}