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.