Mega Code Archive

 
Categories / Java / Swing JFC
 

Prevent the space from being inserted when shift-space is pressed

import javax.swing.JComponent; import javax.swing.JFrame; import javax.swing.JTextField; import javax.swing.KeyStroke; public class Main {   public static void main(String[] argv) {     JTextField component = new JTextField(10);     component.getInputMap(JComponent.WHEN_FOCUSED).put(KeyStroke.getKeyStroke(new Character(' '), 0), "none");     JFrame f = new JFrame();     f.add(component);     f.setSize(300, 300);     f.setVisible(true);   } }