tree cannot be painted in the VE [message #607276] |
Sun, 01 May 2005 19: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;
}
}
|
|
|
Powered by
FUDForum. Page generated in 0.03795 seconds