Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / GUI / December 2005

Tip: Looking for answers? Try searching our database.

Input Verifier for JComboBox

Thread view: 
Tim Frawley - 22 Dec 2005 21:52 GMT
If I create and InputVerifier and set an editable JComboBox like so:

JComboBox myJComboBox = new JComboBox;
myJComboBox.setEditable(true);
myJComboBox.setInputVerifier(comboVerifier);

The Verifier never fires.

Whats the deal.
Michael Dunn - 22 Dec 2005 22:32 GMT
> If I create and InputVerifier and set an editable JComboBox like so:
>
[quoted text clipped - 5 lines]
>
> Whats the deal.

((JTextField)myJComboBox.getEditor().getEditorComponent()).setInputVerifier(comboVerifier);
Tim Frawley - 28 Dec 2005 17:24 GMT
Ok, this works but I cannot access the methods of the JComboBox when
downcasting to a JTextField.

I wanted to verify that the entered value existed on the combo list.
Knute Johnson - 28 Dec 2005 17:52 GMT
> Ok, this works but I cannot access the methods of the JComboBox when
> downcasting to a JTextField.
>
> I wanted to verify that the entered value existed on the combo list.

If the edited value isn't in the list the SelectedIndex will be -1.  If
it is the SelectedIndex will be the index of the value.

Signature

Knute Johnson
email s/nospam/knute/

Tim Frawley - 29 Dec 2005 00:02 GMT
Thanks for the reply Knute.

Can you test the SelectedIndex in the InputVerifier?

((JTextField)cboYear.getEditor().getEditorComponent()).setInputVerifier(comboVerifier);

I don't believe so but I don't know Java well enough to say.

Let me ask this,

If you are writing a data entry application and want to validate a
users input after they enter a value into an editable JComboBox what
event would you say is the best to use?

One of the things I did in these combo boxes was to populate them with
CODE - DESCRIPTION values.  I would like to allow them to type in the
code and then attempt to select the item for them from the value
entered.  Sort of like, auto completion.  That way they wouldn't have
to type the entire code-description value pair.

I also want to be sure that if they copy and paste into the editor my
event will catch it.  I can, of course, do all this when the save
button is clicked but I would like to try it the other way too.

I appreciate your assistance and value your advice.

Sincerely,

Tim Frawley
Knute Johnson - 29 Dec 2005 03:56 GMT
> Thanks for the reply Knute.
>
[quoted text clipped - 3 lines]
>
> I don't believe so but I don't know Java well enough to say.

You will have to have a reference from outside of the InputVerifier I
would think.

> Let me ask this,
>
[quoted text clipped - 17 lines]
>
> Tim Frawley

If you want something to do auto-completion you might try writing a
special purpose Document and use that on a JTextField.  The Document
methods can detect string insertions from either the keyboard or cut and
paste operations.  I think that is where I would start anyway.

Signature

Knute Johnson
email s/nospam/knute/



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.