当前位置: 首页>>代码示例>>Java>>正文


Java JComboBox.setName方法代码示例

本文整理汇总了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);
}
 
开发者ID:max6cn,项目名称:jmt,代码行数:31,代码来源:DefaultsEditor.java

示例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);
}
 
开发者ID:max6cn,项目名称:jmt,代码行数:23,代码来源:DefaultsEditor.java


注:本文中的javax.swing.JComboBox.setName方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。