JFrame frame = new JFrame("Welcome!!");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JComboBox cmb = new JComboBox();
cmb.setEditable(true);
cmb.getEditor().getEditorComponent().addKeyListener(new KeyAdapter() {
@Override
public void keyReleased(KeyEvent event) {
if (event.getKeyChar() == KeyEvent.VK_ENTER) {
if (((JTextComponent) ((JComboBox) ((Component) event
.getSource()).getParent()).getEditor()
.getEditorComponent()).getText().isEmpty())
System.out.println("please dont make me blank");
}
}
});
frame.add(cmb);
frame.setLocationRelativeTo(null);
frame.setSize(300, 50);
frame.setVisible(true);
16 June
Casting JComboBox to JTextComponent to get Key Release event
Subscribe to:
Posts (Atom)
Beyond Toughness: Why Your Car's Brain Needs AEC-Q100 AND ASIL-B
AEC-Q100 vs. ASIL-B: Quality Meets Safety In the era of autonomous driving and electric vehicles, the electron...
-
This will create a certification file and send to free certification authority " https://certbot.eff.org " sponsored by linux foun...
-
Annual Technical Conference 2006 of IET-YMS Sri Lanka, 16 th October 2010 Department of Electrical and Information Engineering, University ...
-
Installing MPICH2 parallel computing from package manager or Ubuntu software center, will need lot configurations of available real processo...