Hello Clemens
Hello again,
It sounds very similar to the bug 4743225
http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4743225
As far as I know there is no any good workaround for this problem,
Oha 68 votes ... thats some kind of funny and sad too. But yes it
seems many people are fighting with this problem.
I also asked to this list because I would like to fix it, when I asked
first I didn't know that there are already some fixes available, but
none of them was compatible enough.
And regarding to the evaluation-statement well ... now its the perfect
time "after mustang" ;)
I wonder which type of compatibility problems could arise? Do you
think some people depend on the behaviour of the not-resizing list?
Is it so risky to simply run the size calculation after the popup
listeners (nobody has access to the popup anyway), or do a
double-calculation (which would be even save for reflection).
Actually this bug has always been a pain for us
because we didn't find any workaround better than
showing popup and hiding it again
which is ugly and cause to popup flickering
combobox is just not ready that its data is changed inside popupListener
you can find my favorite workaround ever in comments for this bug
http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4743225
the idea is to open the combobox and close it after that
with help of awt.Robot
:-)
By the way if you find a reasonable fix I'll be happy to review it
If you are subscribed to the peabody forum,
you can also look to the proposed fixes from Brian Harry for this problem
https://jdk-collaboration.dev.java.net/servlets/ProjectForumMessageView?messageID=12475&forumID=1463
Thanks
alexp
lg Clemens
Actually, there are three options.
The first is to use reflection on the UI delegate to get the protected popup
field. The second is to wrap the original UI delegate and delegate all the
calls to it. Then, you can override the createPopup method and store the
reference to it in your code.
Both are very unlikely to break in the future JDK versions since both popup
field and createPopup method are protected and as such are contract between
Swing and third-party LAFs. The first will break under a strict security
manager (JNLP, applets, ...). The second requires much more work to track
LAF changes and delegate all the public and protected methods.
Yet another option is to call
BasicComboBoxUI.getAccessibleChild() passing 0 as the
second parameter. Here you don't have any guarantees that it won't break
under the future JDK versions, but that would be also highly unlikely.
Kirill
----- Original Message ----
From: Alexander Potochkin <[EMAIL PROTECTED]>
To: [email protected]
Sent: Thursday, August 16, 2007 11:16:23 AM
Subject: Re: <Swing Dev> Updating a JComboBox's values at popup-opening-time
Hello Clemens
It sounds very similar to the bug 4743225
http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4743225
As far as I know there is no any good workaround for this problem, sorry
alexp
Hello,
This is both a question and (if its really a problem) maybe an idea
for enhancement.
I've a JComboBox which should update its values at the time it is
opened (because the come from a source which changes from time to time
during the life of the JComboBox and I don't want to update it
periodically).
What I did was to register a PopupListener and changed the item of the
ComboBox but the problem was that the Popup already existed - and
although its values were updated its size was not.
If I e.g. had 1 entry before the update and 4 afterwards I got a list
with the size of 1 entry with very small scrollbars.
The root of the problem seems to be that there is no legal way to
access the BasicComboPopup (or whatever its called), as far as I've
seen.
Could my stuff be done in another way which would not cause the
problems mentioned above? I currently did a hack which calls
showPopup/hidePopup in the listener so that the too small list is
hidden and afterwards the larger list appears but thats really a hack.
I wonder wether it would be ok to work on that stuff so that the list
re-calculates its size also when items are removed/added when the
popup is already visible? Do you think that could break something?
Please feel free to send commend, I would be really happy about
suggestions.
lg Clemens
________________________________
Choose the right car based on your needs. Check out Yahoo! Autos new Car
Finder tool.