Article View: borland.public.jbuilder.java.swing
Article #520Re: Design window turning red
From: Magnus
Date: Mon, 30 May 2005 16:26
Date: Mon, 30 May 2005 16:26
101 lines
4631 bytes
4631 bytes
Superthanks for your input. Some of it I understand and some of it I don't.
I have followed multiple tutorials and and implemented to fit my need.
This is what I have:
An application where using a tree to display what is in the DB and used
for selection (that then triggers actions). A tree is used in a couple
of different screens. The tree is only to show values and enable easy
navigation and selection.
My tree implementation:
public class MyTree extends JPanel implements TreeSelectionListener {
static final int USED_AT_A = 0; // where tree is implemented
static final int USED_AT_B = 1;
public MyTree(nodeInfo topNode,int type) {
public void valueChanged(TreeSelectionEvent e) {
// this then determine what type it is and use "a ststic method"
// to set selected values. The method to used is determined by
// USED_AT_A or USED_AT_B
public String[] getSelEquip() {
// used from mainFrame to get values
public clear(nodeInfo top) {
// clear the tree and start a new one with top as root
public DefaultMutableTreeNode insertNode (
// used from mainFrame to build the tree
// (i.e. getting data from DB is outside the tree)
public static class nodeInfo {
// My different types of nodes
public String id;
public String ttype;
public String what;
public nodeInfo(String nID, String t, String w) {
id = nID;
ttype = t;
what = w;
}
public String toString() { return id; }
public String getType() { return ttype; }
public String getWhat() { return what; }
} // end nodeInfo
private class MyRenderer extends DefaultTreeCellRenderer {
// used to set cirrect Icons and tooltip depending on type
} // end MyTree
So i create in my panel where I want to work with my tree:
public class mainFrame extends JFrame {
MyTree firstTree;
...
firstTRee = new MyTree(new MyTree.nodeInfo(
"Empty","C", "C"), MyTree.USED_AT_A);
//this creates my empty tree that can be seen in designer.
buildTree(firstTree) { // a method to get DB from DB and to build tree.
Here is where I fail:
1) The listener is iplemented in MyTree (as I thought it should)
2) When a tree selection happens - the listener updates values in the
panel where "firstTree" is implemented. The update use a method that
"must" be static since I can't create a
mainFrame frame = new mainFrame();
within MyTree. (since I in frame have created firstTree) ...
3) Since method used by firstTree.<my static method> is static it
ripples through all functions and GUI components that then will be
updated by a selection in the tree.
So, where have I gone wrong ? How to fix this?
Thanks in advance,
Magnus
Paul Furbacher [TeamB] wrote:
> 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.
>
Technical Details
Message-ID:
<429b3eba$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!news.glorb.com!border1.nntp.dca.giganews.com!nntp.giganews.com!diablo.voicenet.com!news-out.newsgroups.com!propagator2-sterling.newsfeeds.com!in.nntp.be!caladan.landsraad.net!newsgroups.borland.com!not-for-mailReferences:
<42762745@newsgroups.borland.com> <42769338$1@newsgroups.borland.com> <4292a4e3@newsgroups.borland.com> <42932c57@newsgroups.borland.com> <4299abf1$1@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: Mon, 30 May 2005 12:26:40 -0400 From: Magnus <magnus_bjorkman@iwon.com> User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.2) Gecko/20040804 Netscape/7.2 (ax) X-Accept-Language: en-us, en, sv 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> <4299abf1$1@newsgroups.borland.com> In-Reply-To: <4299abf1$1@newsgroups.borland.com> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit NNTP-Posting-Host: 71.0.99.227 Message-ID: <429b3eba$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1117470394 71.0.99.227 (30 May 2005 09:26:34 -0700) Lines: 101 Path: arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!news.glorb.com!border1.nntp.dca.giganews.com!nntp.giganews.com!diablo.voicenet.com!news-out.newsgroups.com!propagator2-sterling.newsfeeds.com!in.nntp.be!caladan.landsraad.net!newsgroups.borland.com!not-for-mail