原来,在动态增加JComboBox 的时候,如果没增加validate()方法 仅仅是使用了 repaint()方法的话,JComboBox的下拉箭头可能会不显示。如:
button_2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
comdef = new ComponentDefined(x,20 + count_add * 20);
// JComboBox j1 = new JComboBox(new String[]{"","OR","AND"});
// j1.setBounds(x, 20 + count_add* 30, 55, 20);
// comdef.setComBox(j1);
// comdef.getComBox().updateUI();
panel.add(comdef.getComBox());
panel.add(comdef.getTextField());
// panel.validate();
panel.repaint();
count_add = count_add +1;
System.out.println(panel.getComponentCount());
}
});
就能容易看到加与不加validate()的效果了。