🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.jbuilder.java.swing
Article #514

Re: Design window turning red

#514
From: Paul Furbacher [TeamB]
Date: Sun, 29 May 2005 11:48
114 lines
6054 bytes
Magnus wrote:

> I did have a problem with a customized tree that was built with values 
> from a DB. 

Shouldn't be designed this way.  Your component should stand
on its own without data.  The classes that use it are the only
ones which should put data into it -- all it should know
how to do is to display the data other classes put into it.
It should not access databases; it should not read files; it
should just sit there like a lump until something else provides
data to it.

> I solved it with an "empty" constructor call in jbInit and 
> then build the tree on another trigger. I also realized that if fields 
> in jbInit are placed in proper order (i.e. red beans in the end) the 
> rest of the fields are looking fine.

That's not really the solution.  If your tree component is truly
designed with a default constructor and does not incorrectly try
to populate itself by accessing a database in that constructor,
you should have no red bean issues to deal with.  It is a view
component, not a model or controller component.

Did you create this custom tree component so that it accesses
a database?  If so, this is definitely the wrong way to go.
Tree = view.  I might even venture to say that all you may
need to do is to write a node class which implements a data-
specific "toString()" method.  Put your database access and
tree model building code in a business object class and simply
write

   MyBusinessObject mbo = new MyBusinessObject(...);
   // where "..." represents database config.
   TreeModel tm = mbo.getDataForParams(...);
   // where "..." represents selection params, etc.

   myStandardJTree.setModel(tm);


in a method other than "jbInit()".

I'm willing to bet that if you refactor your thinking
and design, my comments below will become irrelevant because
JTree already has all the events you need in order to
respond to selection changes, etc.  Again, the tree is
just a view; it should never be the one operating on your
model.

> Now, after I fixed the tree-red bean, I ended up in another "issue". It 
> is not a problem but is as follow:
> - I have my custom tree in its own panel as part of a lot of other 
> fields and graphs etc.
> - My listener for the tree gives me what I need but to be able to update 
> the fields outside the tree panel I have to make all of them static.

There is no reason why you need to define static member variables
of the frame or panel in which an instance of your custom
tree component resides.  How and where did you make the listener
class?  Is it an anonymous nested/inner class of the frame/panel
in which your custom tree resides?  Or did you create it
inside the custom tree's class?  (I suspect the answer is yes
to the latter.)

> - Now I have all fields show up as red beans and all panels and 
> everything is marked static.

With a properly designed event you should be able to plop
your custom tree into your panel/frame using the Designer,
flip to the events tab of the Property Inspector, double-click
on your custom event.  (Assuming you did implement the event;
if not, implement it in the JavaBeans way of doing this.  See
Sun's tutorials on events at their site.)  The Designer will
create the anonymous adapter; you code the details.  Since the
listener adapter is implemented in the frame in which the member
variables you want to access are declared, you have instance-based
access to them.  No need for statics anywhere.

> Question: Is there a way to go from a static environment to a non-static 
> environment. Can I place the tree-listener outside its own object and 
> then trigger everything within the "main" panel.

I think you should be able to answer this question with a bit
of "follow the example" learning: take an ordinary JTree
and ask, how do I provide a listener to one of its standard
events, e.g., a selection event?  Since JTree is already written,
you obviously don't dig into its class source code and add
listeners inside JTree.  Where do you implement the listener?
How should you do this using (focus on "using") your custom
component?  How should you design your custom component so
that other interested classes may register to receive
event notifications?

It may be a good idea to get a book on Swing and review
events, both from designing them into your components,
registering handlers with the components, and so on.  Or
at the very least, work through the events tutorials on
the java.sun site.


-- 


Paul Furbacher (TeamB)

   Save time, search the archives:
        http://www.borland.com/newsgroups/ngsearch.html

   Is it in Joi Ellis's Faq-O-Matic?
        http://www.visi.com/~gyles19/fom-serve/cache/1.html

   Finally, please send responses to the newsgroup only.
   That means, do not send email directly to me.
   Thank you.
Technical Details
Message-ID: <4299abf1$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news.glorb.com!newsfeeder.wxs.nl!news.netcologne.de!newsfeed-fusi.netcologne.de!news-out.newsgroups.com!propagator2-sterling.newsfeeds.com!in.nntp.be!caladan.landsraad.net!newsgroups.borland.com!not-for-mail
References: <42762745@newsgroups.borland.com> <42769338$1@newsgroups.borland.com> <4292a4e3@newsgroups.borland.com> <42932c57@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 111d45,bddfb924687a12a0
X-Google-Attributes: gid111d45,public
X-Google-Language: ENGLISH,ASCII-7-bit
Date: Sun, 29 May 2005 07:48:05 -0400
From: "Paul Furbacher [TeamB]" <pfurbacher@mac.com>
Organization: Reverse Alchemy, Inc.
User-Agent: Mozilla Thunderbird 0.8 (Macintosh/20040913)
X-Accept-Language: en-us, en
MIME-Version: 1.0
Newsgroups: borland.public.jbuilder.java.swing
Subject: Re: Design window turning red 
References: <42762745@newsgroups.borland.com> <42769338$1@newsgroups.borland.com> <4292a4e3@newsgroups.borland.com> <42932c57@newsgroups.borland.com>
In-Reply-To: <42932c57@newsgroups.borland.com>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
NNTP-Posting-Host: 69.142.222.65
Message-ID: <4299abf1$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1117367281 69.142.222.65 (29 May 2005 04:48:01 -0700)
Lines: 114
Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news.glorb.com!newsfeeder.wxs.nl!news.netcologne.de!newsfeed-fusi.netcologne.de!news-out.newsgroups.com!propagator2-sterling.newsfeeds.com!in.nntp.be!caladan.landsraad.net!newsgroups.borland.com!not-for-mail