0

I have a Swing Application with a JTextField that the user is Supposed to Input ID Numbers. The ID Numbers are Stored in a database. During Inquiry from the DB the End user is again required to Input the ID Number so as to Query the DB. I need suggestions as to what to do so that when the user Inputs the First Digits of the ID Number, Guesses appear below the JtextField for the User to Choose from. Is this Possible with Swing and what Is the Best way to Implement it?

mKorbel
  • 109,525
  • 20
  • 134
  • 319
Stanley Mungai
  • 4,044
  • 30
  • 100
  • 168
  • Have you done some research on that already? What was the outcome if so? – Fildor Sep 20 '12 at 11:13
  • Fildor: I would not have asked if I had a solution to it or hadn't serached around and found a solution. It is Ok if you do not want to help. I asked for Ideas Not COdes. – Stanley Mungai Sep 20 '12 at 11:15
  • 2
    This thread may be helpful: http://stackoverflow.com/questions/1216357/drop-down-list-within-jtextfield – fish47 Sep 20 '12 at 11:17
  • I just do not want to tell you "Look there and there" if you have done so already. It always helps a lot to know what the op has already found promising but NOT solving his problem. – Fildor Sep 20 '12 at 11:17
  • @Stanley for why reason is value saved to DB and then distributes from DB back to GUI, nothing against your thread nor about description ... – mKorbel Sep 20 '12 at 11:21
  • mKorbel I need to make it easier for the End user while Querying the DB for Information to Input just a few Characters and the Closest GUess is shown on the GUI for them to select. – Stanley Mungai Sep 20 '12 at 11:26
  • @Stanley Have you checked out the link in my answer? If it is not what you need, please leave a comment in the answer as to why it is not. Then I can see if I can come up with something different. – Fildor Sep 20 '12 at 11:29
  • @Fildor, Yes I have I think it is Talking more of Jcombobox that JTextField. – Stanley Mungai Sep 20 '12 at 11:38
  • I see. So making it a JComboBox is not an option. Then check out the SO link in fish47's comment. It is a solution with JTextField but a little less sophisticated. – Fildor Sep 20 '12 at 11:46

4 Answers4

2

http://www.orbital-computer.de/JComboBox/ Maybe this helps. I know I shouldn't post just a link. But I cannot write everything explained there again here.

Fildor
  • 14,510
  • 4
  • 35
  • 67
1

Try AutoCompleteDecorator in swingx. Check this post.

Community
  • 1
  • 1
basiljames
  • 4,777
  • 4
  • 24
  • 41
1

still not sure,

  • you can to use AutoCompleted JComboBox / JTextField (AFAIK ther no issues with Document, Focus, Caret and Selection/HightLighter)

  • (and to combine with a.m. point) to use filtering in JTable (with one Column and/or without JTableHeader) placed in the undecorated JDialog or JWindow(undecorated by default) in case that you want to display popup window with long list of sentences in the scrollabel contents, that could be clickable

    1. use Swing Timer (5 -10 seconds for autohide for popup window)

    2. share (use the same) model for JTable and AutoCompleted JComboBox / JTextField based on Vector or ArrayList,

    3. to check focus lifecycle (nothing better aroung) for popup window as Java Calendar by Kai Toedter (download codesource)

Community
  • 1
  • 1
mKorbel
  • 109,525
  • 20
  • 134
  • 319
0

You should write a PickList class which must contain a SQL Query select * from dbtableName where empId %getUserInput()%;