To filter out the characters you don't want you can override this method of
Document/PlainDocument

public void insertString(int offs, String str, AttributeSet a)

In the implementation, call super.insertString() for those characters you
want to pass thru to the text field, but don't call it for those you want to
consume.

-----Original Message-----
From: Roger Talkov
To: Advanced-Swing (E-mail)
Sent: 2/22/02 9:57 AM
Subject: RE: What's the recommended way to prevent keyboard input to a text
field?

do a GetEditor().getEditorComponent () to get the JTextField , and the
set a Document (extend PlainDocument) on it which will filter out
undesirable input.

-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]On
Behalf Of Vella, John
Sent: Thursday, February 21, 2002 9:56 PM
To: Advanced-Swing (E-mail)
Subject: What's the recommended way to prevent keyboard input to a text
field?


I need to use an editable JComboBox where I want to prevent the user
from
typing any characters other than the caret-control keys(like the
left/right
arrows, home, end, etc). The text shown in the text field could be long,
which is why it's important for my users to be able to scroll it.
However I
need to prevent them from actually typing into the text field. I'll
support
using DnD to get text into the field or the use of the combobox's
dropdown
list.

So my question is: what is the "best way" to prevent users from typing
anything into the text field but still allowing caret position control?

Thanks,

John  (using 1.3.1)

_______________________________________________
Advanced-swing mailing list
[EMAIL PROTECTED]
http://eos.dk/mailman/listinfo/advanced-swing
_______________________________________________
Advanced-swing mailing list
[EMAIL PROTECTED]
http://eos.dk/mailman/listinfo/advanced-swing

Reply via email to