Prevent the space from being inserted when shift-space is pressed. : Document Event « Swing JFC « Java






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);

  }
}

   
    
    
    
  








Related examples in the same category

1.DocumentFilter that maps lowercase letters to uppercaseDocumentFilter that maps lowercase letters to uppercase
2.An extension of PlainDocument that restricts the length of its contentAn extension of PlainDocument that restricts the length of its content
3.Document Event DemoDocument Event Demo
4.React to the document update insert changed eventReact to the document update insert changed event
5.HTMLDocument: Document Iterator Example
6.DocumentListener DemoDocumentListener Demo
7.extends PlainDocument to create a float value type text field
8.extends PlainDocument to create alpha and numeric value based field field
9.Implement a document cleaner that maps lowercase letters to uppercaseImplement a document cleaner that maps lowercase letters to uppercase
10.Document ElementIterator DemoDocument ElementIterator Demo
11.Format JTextField's text to uppercase
12.Overriding a Few Default Typed Key Bindings in a JTextComponent
13.Overriding - key
14.Override $ key
15.Overriding space key
16.Disable a character so that no action is invoked.
17.Bind a keystroke to shift-space
18.Subclass InputVerifier
19.extends PlainDocument
20.This Document restricts the size of the contained plain text to the given number of characters.
21.A frame with three text fields to set the background color.