【发布时间】:2014-03-24 09:05:20
【问题描述】:
在我的项目中,我有一个空的组合框,单击它后我想填充它。
comboCurrent = new JComboBox<String>();
comboCurrent.setBounds(265, 181, 80, 20);
add(comboCurrent);
comboCurrent.setEditable(true);
comboCurrent.setSelectedItem(null);
comboCurrent.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
// TODO populate here
System.out.println(e);
}
});
但不知何故,动作监听器在这里不起作用。 有没有办法在组合框还是空的时候收听第一次点击?
【问题讨论】:
-
comboCurrent.setBounds(265, 181, 80, 20);Java GUI 可能必须在多个平台、不同的屏幕分辨率和使用不同的 PLAF 上工作。因此,它们不利于组件的精确放置。要为强大的 GUI 组织组件,请改用布局管理器或 combinations of them,以及 white space 的布局填充和边框。 (也许你应该给组合一个Default Text..)
标签: java swing focus jcombobox