Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / GUI / January 2004

Tip: Looking for answers? Try searching our database.

Why doesn't Set interface work for UIDefaults?

Thread view: 
hiwa - 14 Jan 2004 09:46 GMT
Swing UIDefaults is an Hashtable. But its Set interface is utterly unusable.

<code>
UIDefaults udf = UIManager.getDefaults(); //udf.size() returns 568
Set defs = udf.entrySet(); //defs.size() returns 0 !!
Iterator itr = defs.iterator(); //so, this code doesn't work
while (itr.hasNext()){
 Map.Entry mentry = (Map.Entry)(itr.next());
 System.out.println
  (mentry.getKey().toString() + " : " + mentry.getValue().toString());
} /* keySet() and values() also don't work */
</code>

After three days/nights struggle, I've found a solution on this forum which
uses old Enumeration interface instead of Set.

<code>
.....
Enumeration enm = udf.keys();
while (enm.hasMoreElements()){
 Object key = enm.nextElement();
 Object value = udf.get(key);
 .....
} /*This code perfectly works !!*/
</code>

Then, you might see my question in the post subject line.
Why on earth the Set interface doesn't work for UIDefaults which is
an Hashtable?
Christian Kaufhold - 14 Jan 2004 10:30 GMT
> Swing UIDefaults is an Hashtable. But its Set interface is utterly unusable.

http://developer.java.sun.com/developer/bugParade/bugs/4821584.html

Christian
Alan Moore - 14 Jan 2004 11:36 GMT
>Swing UIDefaults is an Hashtable. But its Set interface is utterly unusable.
>
[quoted text clipped - 25 lines]
>Why on earth the Set interface doesn't work for UIDefaults which is
>an Hashtable?

I just spent a few hours banging head against this one myself.  I was
trying to iterate through all the "XXX.font" settings in the Metal L&F
and change them from bold to plain style, but it wasn't working.  I
finally just hard-coded the keys, because it never occurred to me that
the Enumeration might work when the Iterator didn't.  But, after
reading this post, I tried it, and it works just fine.

There are two bug reports (4821584 and 4813448) open against this
problem, but they don't seem too eager to fix it.  I think they've
realized that it was a mistake to have UIDefaults extend Hashtable,
but it's too late to change it now (same as with Properties).  But
they could at least put something in the docs to warn us about this
little booby trap.
hiwa - 17 Jan 2004 01:40 GMT
> <code>
> .....
[quoted text clipped - 5 lines]
> } /*This code perfectly works !!*/
> </code>

This code doesn't bring the resourcebundle-type keys up, such as
OptionPane.okButtonText et al.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.