<Swing Dev> Updating a JComboBox's values at popup-opening-time
Kirill Grouchnikov
kirillcool at yahoo.com
Thu Aug 16 18:51:08 UTC 2007
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 <Alexander.Potochkin at Sun.COM>
To: swing-dev at openjdk.java.net
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
____________________________________________________________________________________
Moody friends. Drama queens. Your life? Nope! - their life, your story. Play Sims Stories at Yahoo! Games.
http://sims.yahoo.com/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.openjdk.java.net/pipermail/swing-dev/attachments/20070816/175803ae/attachment.html>
More information about the swing-dev
mailing list