 |
How to use "undocumented secret" Swing properties
Posted by kirillcool on August 16, 2005 at 03:59 AM | Comments (13)
A spurious outburst of "undocumented secret" features of Swing keep popping up lately. The word "undocumented" seems to imply that no official Java documentation on Sun mentions them, and it's only after hours of poring over the JDK code the authors finally distilled these gems. Let's start then?
- swing.defaultlaf that sets the default look and feel is well documented in UIManager javadocs. The fact that most of Java applications are unaware that they should check this setting before installing their own doesn't mean that this property is undocumented.
- JTree.lineStyle for line style in Metal JTree appears not only in javadocs for MetalTreeUI, but also in (rather outdated) Sun tutorial on using trees.
- swing.boldMetal for bold font settings in controls appears proudly in javadocs for MetalLookAndFeel
- JToolBar.isRollover for rollover effects in toolbars appears in twelve bugs on bugparade and on 460+ entries on Yahoo search.
As amptly put in one of the reviews, did they actually mean to call this book "Swing Hacks For People Who Haven't Read Sun's Java Tutorial". The word "undocumented" is out of place here and should be replaced by "seldom-used". The word "secret" is also out of place (the sources are open, as well as plethora of online tutorials and books) and should be replaced by "little-known".
Bookmark blog post: del.icio.us Digg DZone Furl Reddit
Comments
Comments are listed in date ascending order (oldest first) | Post Comment
-
Kirill,
Do not take it personal... People use the words "secret" and "undocumented" just to bring attention to their articles, blogs and books.
Everyone knows that Sun is not Microsoft, and every little Java feature is documented somehere and is "googleisable" :)
Yakov Fain
http://www.weekendwithexperts.com
Posted by: yfain on August 16, 2005 at 06:23 AM
-
I'm with Kirill on this one.
It bothers me slightly that someone is trading off an untruth.
I'm sure the large part of Swing Hacks could be replaced with an insert that says "RTFM."
Posted by: goron on August 16, 2005 at 08:43 AM
-
You may decide to split hairs over the use of the word "undocumented", but Joshua/Romain still do the Swing world a favor by collecting in one place all of these command-line options. Such an exercise was dearly needed.
Posted by: sumitkishore on August 16, 2005 at 09:08 AM
-
That's where lies the difference between journalists/writers and programmers... as Yakov says, it is a way to draw interest to the article. Sure an article called "Little known properties for people who don't take the time to read through the whole JavaDoc" would be more precise but in the end, both titles mean the same to me.
Every "little known" property I use, I found it by browsing the JDK's source code or by searching for "get property" statements. Would I have ever thought of looking at MetalTreeUI documentation? Heck no.
If you like that kind of exercise we can do that for virtually anything ever written by any developer about his stuff. Let's take a look at your statement for Substance:
The goal of this project is to provide a modern look & feel that combines the best features of Windows XP and MacOS 10.4
The best features? Says who? I don't think you picked the best features. It would be more accurate to say the features I enjoy the most. So your sentence would become:
The goal of this project is to provide a look & feel I think is modern that combines the features I like the most from Windows XP and MacOS 10.4
Which version is more attractive?
Oh and by the way, you'd be surprised to see how many programmers do NOT read the bug parade, and do NOT read the whole JavaDoc :)
Posted by: gfx on August 16, 2005 at 11:52 AM
-
I was wondering why, if these properties were indeed documented, I had not come across them (apart from the fact that Javadoc-hunting is not among my favorite sports). Yup, javadoc for these properties that Kirill refers to were added only in JDK5.0.
Kirill might be right on technical grounds, but these properties were as well as undocumented. Looking into Javadoc kind of implies you already know where and how different properties apply - not the best way to learn about new ways to play (a bit) with Swing.
I hold off on commenting upon the O'Reilly article, but at least with efforts like this list, these guys are doing us a favor. Sun should have done this long ago. They keep holding off, ostensibly because some properties might not be guaranteed to be supported. They had a similar argument about jvm options. Then they published this, and the sky didn't fall.
Posted by: sumitkishore on August 16, 2005 at 12:57 PM
-
Sure but take the example of the swing.aatext property in J2SE 5. It has been removed from Java SE 6 and I'm sure we'll get some complains about the fact AA does not work (even though this should be a seldom case since Mustang just applies default settings).
Posted by: gfx on August 16, 2005 at 01:08 PM
-
Romain,
I'm confused now. On one hand, javadoc comments should be the only definitive place that comment the code. When some property is not supported, it's removed from the Javadocs. On the other hand, you wish to maintain a Wiki site with the settings, some of them for specific JDK version, some for specific LAF, some for specific component (as client property). Reinventing the Javadoc? If i'm too lazy to look in the Javadoc, why would i search the Wiki?
Posted by: kirillcool on August 16, 2005 at 01:19 PM
-
The difference is you know what you were looking for. Like in the case of JToolBar.isRollover. You said it appears in the bug parade and so forth but you did know about this property and looked for it. What if I just want to browse a bunch of properties in case one could be useful to me? Do I have to inspect the JavaDoc and find properties hidden in some weird classes I never use directly, like MetalTreeUI? I understand your point here, but I think both the JavaDoc and a Wiki can and must co-exist. They don't address the exact same needs.
Posted by: gfx on August 16, 2005 at 01:30 PM
-
I agree completely, you shouldn't have to read the Javadoc for every class to locate some seldom used property, the existence of exhaustive lists of user settable properties makes locating those which might be useful to you as a developed makes things so much easier, and sorry, I do not count bug reports as part of the official documentation.
Posted by: fred33 on August 16, 2005 at 02:59 PM
-
A quick search in gougle groups reveals that e.g. the JTree.lineStyle property was discussed way back in March 1998 on Usenet in the comp.lang.java.gui newsgroup. Just two month later someone posted the complete UIManager properties list, which was subsequently discussed. And this might not be the first occurances of the properties in public.
Calling the properties a secret stretches things more than a little bit. They have been in the open for at least seven years.
Posted by: ewin on August 17, 2005 at 12:43 PM
-
ewin: That's why everybody knows them.
Posted by: gfx on August 17, 2005 at 07:36 PM
-
Romain,
Scenario:
On Monday Romain and Joshua publish a Wiki page with Swing properties
On Tuesday all Swing developers (not only current, but also future) find out and start using them
Sounds a little bit stretched... In a year this page will be long forgotten, and hordes of new Swing programmers will "rediscover" them. Wiki is not panacea, you know.
Posted by: kirillcool on August 18, 2005 at 03:32 AM
-
Kirill,
The difference is
(1) These guys are the authors of 'Swing Hacks'. In all these years of Java, only 3-4 resources have stuck in my mind. One is the online Java tutorial. Another used to be the Swing Sightings page. 'Swing Hacks' is going to be one of them, because whether or not these guys are pioneering geniuses, they discuss interesting things beyond the beginner Swing tutorial.
(2) The wiki is on the java.net site. I would have been happier if it (or a similar list) was given pride of place on the JavaDesktop homepage, but this is second-best. In comparing to previous mentions in some tech note or so, you forget that these were mentions of one property at a time. I would hardly bookmark one such note. I will bookmark a list of them.
Ewin, Kirill,
You guys just prove your geekiness. Do you actually design Swing GUIs as well?
Posted by: sumitkishore on August 18, 2005 at 01:13 PM
|