tree cannot be painted in the VE [message #89099] |
Sun, 01 May 2005 23:36 |
Eclipse User |
|
|
|
Originally posted by: tischercd.hotmail.com
For create my tree and change the default code in
getJTree-Method: jTree = new JTree()
to the following: jTree = new JTree(rootNode);
the tree cannot be painted in the VISUAL EDITOR!
Can you explain this with code sample?
thanks
// Java Code
import javax.swing.JFrame;
import javax.swing.JTree;
import javax.swing.tree.*;
public class visual extends JFrame {
private javax.swing.JPanel jContentPane = null;
private JTree jTree = null;
private JTree getJTree() {
if (jTree == null) {
TreeNode rootNode = createNodes();
jTree = new JTree(rootNode);
}
return jTree;
}
private TreeNode createNodes() {
DefaultMutableTreeNode root;
DefaultMutableTreeNode grandparent;
DefaultMutableTreeNode parent;
DefaultMutableTreeNode child;
root = new DefaultMutableTreeNode("San Francisco");
grandparent = new DefaultMutableTreeNode("Potrero Hill");
root.add(grandparent);
parent = new DefaultMutableTreeNode("Restaurants");
grandparent.add(parent);
child = new DefaultMutableTreeNode("Thai Barbeque");
parent.add(child);
child = new DefaultMutableTreeNode("Goat Hill Pizza");
parent.add(child);
return root;
}
public static void main(String[] args) {
visual application = new visual();
application.show();
}
public visual() {
super();
initialize();
}
private void initialize() {
this.setDefaultCloseOperation(javax.swing.JFrame.EXIT_ON_CLO SE);
this.setSize(300,200);
this.setContentPane(getJContentPane());
this.setTitle("Application");
}
private javax.swing.JPanel getJContentPane() {
if(jContentPane == null) {
jContentPane = new javax.swing.JPanel();
jContentPane.setLayout(new java.awt.BorderLayout());
jContentPane.add(getJTree(), java.awt.BorderLayout.CENTER);
}
return jContentPane;
}
}
|
|
|
Re: tree cannot be painted in the VE [message #89129 is a reply to message #89099] |
Mon, 02 May 2005 02:29 |
Eclipse User |
|
|
|
Originally posted by: myersj.nospam.gmail.com
Tischer wrote:
> For create my tree and change the default code in getJTree-Method:
> jTree = new JTree()
> to the following: jTree = new JTree(rootNode);
> the tree cannot be painted in the VISUAL EDITOR!
>
> Can you explain this with code sample?
Tischer,
The Visual Editor can not visually model classes that are instantiated
with a parameter. The Swing support is based on the Java Beans spec,
which stipulates that classes should have a no-argument constructor, and
any properties of the class are set using set methods.
You can get around the problem in your code this way:
private DefaultTreeModel getDefaultTreeModel() {
if (defaultTreeModel == null) {
defaultTreeModel = new DefaultTreeModel();
defaultTreeModel.setRoot(createNodes());
}
return defaultTreeModel;
}
private JTree getJTree() {
if (jTree == null) {
jTree = new JTree();
jTree.setModel(getDefaultTreeModel());
}
return jTree;
}
The tree still won't show the nodes, but at least it'll show up in the
design view. This is because VE won't execute the createNodes() method
at design time.
Hope this helps,
- Jeff
|
|
|
Re: tree cannot be painted in the VE [message #89144 is a reply to message #89129] |
Mon, 02 May 2005 09:47 |
Eclipse User |
|
|
|
Originally posted by: leafy.nospam.com.tw
"Jeff Myers" <myersj@nospam.gmail.com>
???????:d543eo$b86$1@news.eclipse.org...
> Tischer,
>
> The Visual Editor can not visually model classes that are instantiated
> with a parameter. The Swing support is based on the Java Beans spec,
> which stipulates that classes should have a no-argument constructor, and
> any properties of the class are set using set methods.
>
Is there any plan to overcome this subtlety? Likewise, VE cannot process
anonymous inner classes, so something like:
new JTable(){
public void isCellEditable(){
return false;
}
}
will fail for VE.
Jiawei Ye
|
|
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.04239 seconds