我正在为应用程序制作一个对话框。我想根据组合框的值从其他字段(例如 textField)中获取值。谁能告诉我如何链接这两个组件?-提前致谢
问问题
322 次
1 回答
1
没有神奇的方法可以将组件“链接”在一起。根据您的问题,我了解到您想根据当前选择的组合框或类似的东西来解释文本字段中的数据?因此,当您读取数据时,请使用JComboBox.getSelectedItem()/getSelectedIndex()
您的逻辑。
如果要根据当前选择更改其他字段中的数据或禁用它们,请添加侦听器:
comboBox.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
int index = combo.getSelectedIndex();
if (index == 0) {
//disable some textfields or change format if it's a JFormattedField
}
}
});
于 2010-09-25T05:14:24.140 回答