From: Joshua Cranmer on
On 02/17/2010 02:33 AM, Roedy Green wrote:
> On Mon, 15 Feb 2010 07:53:08 -0500, Joshua Cranmer
> <Pidgeot18(a)verizon.invalid> wrote, quoted or indirectly quoted someone
> who said :
>
>> Traditionally, I make all of my custom panes extend JPanel; I can't
>> really think of a good case where JFrame needs to be extended: if I need
>> to make a powerful main window, I would likely just create a Main-ish
>> class that extends nothing and constructs the elaborate JFrame.
>
> Can you please enumerate the reasons you would not extend a JFrame or
> JPanel? It seems to me when you do, you nicely encapsulate, with
> getters and private variables. What are the advantages of doing it the
> other way?

Whenever I make a GUI, I've tended to think a lot more in terms of
bundles of components. In my most recent example, I essentially have a
StatisticsPane--a little window widget that contains displays of a set
of statistics. This is a pane, so it can be included somewhere in a
dialog, so it must be a JPanel (which is my reasoning for extending
JPanel: it's ultimately a JComponent, and JPanel is the most convenient
for me to extend).

Similarly, even the full, large window I have is merely a bundle of
components. Again, by that rationale, it can be contained in a
theoretically even larger program, so it shouldn't be a JFrame, it's a
JPanel. That's why I can't think of good times to extend JFrame: even
the large set of components is ultimately a bundle of components that
can be included elsewhere, perhaps having a related menu bar that may
need to be included as well.

I will admit that I probably am incorrectly extending JPanel to make all
of my panes (JComponent or even Container is probably better). I make my
panes components because I see them as atomic, indivisible visual areas
which are logically connected and can be independently used and
manipulated. I can use the StatisticsPane without having to use the
HistoryPane or ReviewPane, but I can't really use half of the ReviewPane
and still have a GUI that would make sense, for example.

--
Beware of bugs in the above code; I have only proved it correct, not
tried it. -- Donald E. Knuth
From: Roedy Green on
On Tue, 16 Feb 2010 23:33:42 -0800, Roedy Green
<see_website(a)mindprod.com.invalid> wrote, quoted or indirectly quoted
someone who said :

>Can you please enumerate the reasons you would not extend a JFrame or
>JPanel? It seems to me when you do, you nicely encapsulate, with
>getters and private variables. What are the advantages of doing it the
>other way?

I have collected your thoughts at
http://mindprod.com/jgloss/jframe.html#ISAVSHASA

If I missed something, please let me know.
--
Roedy Green Canadian Mind Products
http://mindprod.com

Nothing has really happened until it has been recorded.
~ Virginia Woolf (born: 1882-01-25 died: 1941-03-28 at age: 59)