Class JosmTextField

All Implemented Interfaces:
ComponentListener, FocusListener, ImageObserver, MenuContainer, PropertyChangeListener, Serializable, EventListener, Accessible, Scrollable, SwingConstants, Destroyable
Direct Known Subclasses:
AutoCompletingTextField, AutoCompTextField, DisableShortcutsOnFocusGainedTextField

Subclass of JTextField that:
  • adds a "native" context menu (undo/redo/cut/copy/paste/select all)
  • adds an optional "hint" displayed when no text has been entered
  • disables the global advanced key press detector when focused
  • implements a workaround to JDK bug 6322854

This class must be used everywhere in core and plugins instead of JTextField.
Since:
5886
See Also:
  • Field Details

  • Constructor Details

    • JosmTextField

      public JosmTextField(Document doc, String text, int columns)
      Constructs a new JosmTextField that uses the given text storage model and the given number of columns. This is the constructor through which the other constructors feed. If the document is null, a default model is created.
      Parameters:
      doc - the text storage to use; if this is null, a default will be provided by calling the createDefaultModel method
      text - the initial string to display, or null
      columns - the number of columns to use to calculate the preferred width >= 0; if columns is set to zero, the preferred width will be whatever naturally results from the component implementation
      Throws:
      IllegalArgumentException - if columns < 0
    • JosmTextField

      public JosmTextField(Document doc, String text, int columns, boolean undoRedo)
      Constructs a new JosmTextField that uses the given text storage model and the given number of columns. This is the constructor through which the other constructors feed. If the document is null, a default model is created.
      Parameters:
      doc - the text storage to use; if this is null, a default will be provided by calling the createDefaultModel method
      text - the initial string to display, or null
      columns - the number of columns to use to calculate the preferred width >= 0; if columns is set to zero, the preferred width will be whatever naturally results from the component implementation
      undoRedo - Enables or not Undo/Redo feature. Not recommended for table cell editors, unless each cell provides its own editor
      Throws:
      IllegalArgumentException - if columns < 0
    • JosmTextField

      public JosmTextField(String text, int columns)
      Constructs a new JosmTextField initialized with the specified text and columns. A default model is created.
      Parameters:
      text - the text to be displayed, or null
      columns - the number of columns to use to calculate the preferred width; if columns is set to zero, the preferred width will be whatever naturally results from the component implementation
    • JosmTextField

      public JosmTextField(String text)
      Constructs a new JosmTextField initialized with the specified text. A default model is created and the number of columns is 0.
      Parameters:
      text - the text to be displayed, or null
    • JosmTextField

      public JosmTextField(int columns)
      Constructs a new empty JosmTextField with the specified number of columns. A default model is created and the initial string is set to null.
      Parameters:
      columns - the number of columns to use to calculate the preferred width; if columns is set to zero, the preferred width will be whatever naturally results from the component implementation
    • JosmTextField

      public JosmTextField()
      Constructs a new JosmTextField. A default model is created, the initial string is null, and the number of columns is set to 0.
  • Method Details