• Post Reply Bookmark Topic Watch Topic
  • New Topic

Something wierd happening regard to JComboBox  RSS feed

 
Esmaeil Ashrafi
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK, lets see :


Please run it, it seems that something is going wrong in line #41 , I'm not sure it is JComboBox problem or not?!

Would somebody please explain that ?

Thanks in advance
 
Rohit Kedia
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please let us know what do you want ... I executed it and every time I type a key then some predefined data is being added to the Combo...
 
Esmaeil Ashrafi
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rohit Kedia wrote:Please let us know what do you want ... I executed it and every time I type a key then some predefined data is being added to the Combo...

You are right, i added a few comments to the snippet...

I expect that in KEY_TYPED event (process of keyTyped method i implemented in class ComboBoxEditorKeyListener), JUST values which of array "values" that has a prefix equal to user typed in String, to be added to combo box, but in any key event, without consideration of comparison, the whole array elements will be added to combo box
 
Rob Camick
Ranch Hand
Posts: 2756
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well add a System.out.println(...) to your code in the loop to see what the values of "value" and "typedValue" are and then you will be able to see if the code is executed or not.
 
Esmaeil Ashrafi
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh Rob, thank you so much

Actually I always use System.out.println(...), but this time i didn't put it at the right place to debug. upon your suggestion
i put two of it just as the fist statements in the loop and found out that the typed in string value obtained by (String) editor.getItem() is null (actually prints nothing > "") !

I did a lot of modifications to the listener and the final is as below:


Although it seems to work fine mostly as expected, but is gotten kinda complicate, and the issue is:
Why editor.getItem() doesn't return the expected value (in the first snippet?

I am going to check its source and if got any better approach, will inform you, but i will watch if you have better suggestion to apply to this case and will appreciate...

Regards
 
Esmaeil Ashrafi
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Edited seems i am mistaken, i should be sure.....

sombody please delete this post...
 
Esmaeil Ashrafi
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Guess what !
I checked the source code of BasicComboBoxEditor and see there shouldn't be any problem with ComboBoxEditor.getItem() method, aaaaaaaaaaaaaaaaaaaaaaaaaaaaand:

I tried both keyTyped and keyPressed methods of KeyListener, but never keyReleased !!!

So the first approach (the simple one) will also do the job. (by means of invoking keyReleased(KeyEvent e) mehod)


This seems better and just perfect...



It seems to be resolved. Thank you
 
Esmaeil Ashrafi
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is just one small problem in the final program (program in previous post) :
Sometimes , when a letter that several values in the list starts with that, is typed, popup doesn't show itself! and when for example i maximize the window, it appears as expected.
I even put the before , but has no affect.

Attached picture explains more

Thanks in advance.
popUp incomplete.JPG
[Thumbnail for popUp incomplete.JPG]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!