Why would I do something like that?

"It's easy to customize the content pane ?setting the layout manager or adding a border, for example. However, there is one tiny gotcha. The getContentPane method returns a Container object, not a JComponent object. This means that if you want to take advantage of the content pane's JComponent features, you need to either...

1) typecast the return value or...

2) create your own component to be the content pane. Our examples generally take the second approach, since it's a little cleaner.

3) Another approach we sometimes take is to simply add a customized component to the content pane, covering the content pane completely."

- Sun (http://java.sun.com/docs/books/tutorial/uiswing/components/rootpane.html)

My question is why in the world would I EVER what to take the 3. approach!? Just to show that I'm clever(?) or does it give me any benefits in some cases? If so, what are they?

Regards,

Stefan

[964 byte] By [StefanHansena] at [2007-11-26 21:05:05]
# 1
option 3 is a little weak, but if all you're doing is building a little piece of code as an example, or something where memory performance isn't a big issue it's not so bad
tjacobs01a at 2007-7-10 2:38:29 > top of Java-index,Desktop,Core GUI APIs...
# 2

3 doesn't offer any benefits really, although it's not the crime of the century either. You might want to use it if for instance you wanted to add an empty border as a margin around your UI component - though you could still achieve this with a bit more control and an extra two lines of code via 2. 1 is unpleasant. 2 is the way I would advise doing it.

itchyscratchya at 2007-7-10 2:38:29 > top of Java-index,Desktop,Core GUI APIs...
# 3
But it ain't easier or faster than option 2 or simply using the default content pane. So, I see no point (except "being clever").
StefanHansena at 2007-7-10 2:38:29 > top of Java-index,Desktop,Core GUI APIs...
# 4

I don't think it's "being clever," it's just a different way of doing it, which to my mind is neither as logically clean as 2 nor as efficient.

Just because there's no good reason for doing it doesn't mean it's not possible. I didn't notice the quoted text actually advocating 3, it just says you can do it.

itchyscratchya at 2007-7-10 2:38:29 > top of Java-index,Desktop,Core GUI APIs...