Win a copy of Java Concurrency Live Lessons this week in the Threads forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

phantom items in jcombobox  RSS feed

 
antonio espinosa
Ranch Hand
Posts: 30
Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator



I've been developing a small application and founded this problem; when i add new elements to jcombobox model sometimes the jcombobox displays blank spaces, but you can see the elements because of this and when you select them they appear. http://img443.imageshack.us/img443/9675/sdjs.png


please help i'm very stuck at this
 
Ranganathan Kaliyur Mannar
Bartender
Posts: 1103
10
Java Netbeans IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
It is quite difficult to find the issue from this code. I suggest you create a small, runnable program that reproduces the issue. And post that code. This is called SSCCE.
 
antonio espinosa
Ranch Hand
Posts: 30
Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i think here it is. short runable and just what it matters. Please help me

 
Paul Clapham
Sheriff
Posts: 22185
38
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One of the C's in SSCCE is "compilable". That code isn't compilable, it's full of references to classes like ArrayListComboBoxModel which aren't part of the standard API. If we have to download other software to run your code, then you should tell us that. (But don't be surprised if people don't really want to download other software.)
 
antonio espinosa
Ranch Hand
Posts: 30
Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
just have a look at this

each square contains an item but it does not display properly and it's not the render i added a render just like javatutorials and the same problem happen
 
Paul Clapham
Sheriff
Posts: 22185
38
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You could make your code a lot shorter. For example your KeyListener probably isn't part of the problem so you could get rid of that. (In fact you probably don't need a KeyListener at all, that isn't the way to tell if an entry in a combo box is selected, but that's another issue.) And you could remove the code which sets the fonts, too, that probably isn't related to the problem. For that matter you could remove the code which sets the foreground colour too. (What colour is that anyway? Is it the same as the background?)
 
antonio espinosa
Ranch Hand
Posts: 30
Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i've reduced the problem significantly but time in time the same happens, i just added a custom renderer and a custom editor . i also attach the project for studys porposes May be some one can buy some time with this
project
 
Tony Docherty
Bartender
Posts: 3210
78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
antonio espinosa wrote:i've reduced the problem significantly but time in time the same happens, i just added a custom renderer and a custom editor

It's rather hard to help without an SSCCE as Paul has already stated. Without one we are just guessing at what the problem is.
My guess is it due to you adding components to the model in the KeyListener. Is that code supposed to be adding components to the model as the user types into the editor and is this when it is failing?
 
antonio espinosa
Ranch Hand
Posts: 30
Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is that code supposed to be adding components to the model as the user types into the editor and is this when it is failing?
that's it

this is my very best to do SSCC but since i'm using Hinernate 3.6.10 i'll have to include all the libraries and mapping stuff , also i'm implementing a special model and render (wich is included), now the database is also included just add the packages and if you use netbeans just import it. the starting point is itemseller
http://sdrv.ms/15gDB2s

my regards
 
Tony Docherty
Bartender
Posts: 3210
78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why does your SSCCE require hibernate, surely you only need the GUI stuff to reproduce the problem.
 
antonio espinosa
Ranch Hand
Posts: 30
Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
because i get the results from a database via hibernate query. the combobox is a product searcher as i'm typing something, similar products are added to results for later selection.this means jcombobox model's updates it's data when typing remplacing old values with news matching
 
Ranganathan Kaliyur Mannar
Bartender
Posts: 1103
10
Java Netbeans IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
antonio espinosa wrote:because i get the results from a database via hibernate query.

Yes, but, we want to run your program and simulate the issue. It is not possible for us to setup a database to do it. Hence the suggestion to provide a SSCCE - a small runnable program which anyone would be able to copy and run.
 
antonio espinosa
Ranch Hand
Posts: 30
Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
try this
 
Tony Docherty
Bartender
Posts: 3210
78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you explain what is supposed to happen when you enter some value into the JCombobox and what is actually happening for a given input.
Also can you explain what line 77 is supposed to do because I reckon it will always return 0 - it is effectively saying get me the index of the item at index 0.
 
antonio espinosa
Ranch Hand
Posts: 30
Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tony Docherty wrote:Can you explain what is supposed to happen when you enter some value into the JCombobox and what is actually happening for a given input.
Also can you explain what line 77 is supposed to do because I reckon it will always return 0 - it is effectively saying get me the index of the item at index 0.


since i have to give you a copy paste example that reproduces the problem ... this is the best thing i can do to fake a hibernate search(when i enter values a search is made wich look for similar name products) so it dosen't matter if it allways returns an object in position 0(it's simulating a search).

you must see the fact when droping down the combobox, the item or items founded are not printed, it's in the model but it's not printed (THAT IS the real problem here) exactly like this http://imageshack.us/a/img42/2892/a0m5.png
 
Tony Docherty
Bartender
Posts: 3210
78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I changed the key listener to:



And it sort of worked in that it added the item to the list but did so twice - it's only adding one item to the arraylist so I suspect the double posting is from your renderer.
 
antonio espinosa
Ranch Hand
Posts: 30
Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank you but still not working =(
 
Ranganathan Kaliyur Mannar
Bartender
Posts: 1103
10
Java Netbeans IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
antonio espinosa wrote: the item or items founded are not printed, it's in the model but it's not printed (THAT IS the real problem here)

That is because, you have not notified the GUI that the model has changed. And that is done by calling one of the convenient super.fireXXX methods. So, you need to call super.fireContentsChanged(this, -1, -1) in the addElements() method (after the item is added to the model).
 
antonio espinosa
Ranch Hand
Posts: 30
Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Very well my friend, it worked like a charm. i added the fireContentsChanged in the model's addElements and the dropdown list updated thank you a lot. the only problem here was when just one match appeared i could not edit the text, it selected automaticaly the match but i fix this with a model.getselecteditem(null); . How can i fix this from the model class? any ideas
 
Ranganathan Kaliyur Mannar
Bartender
Posts: 1103
10
Java Netbeans IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok, good.
I am simply unable to understand your latest issue. I remember from the code that, when user enters characters, the search is narrowed down. I don't remember it auto-selecting anything on its own.
 
antonio espinosa
Ranch Hand
Posts: 30
Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
that's just what the issue is But it only happens when one item is found. as you type it always selects the same item putting the whole text in combo text input
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!