java - Jtree inside JScrollPanel not working -
defaultmutabletreenode mycomputer = new defaultmutabletreenode("my computer"); defaultmutabletreenode c = new defaultmutabletreenode("local disk(c:)"); defaultmutabletreenode vinod = new defaultmutabletreenode("vinod"); defaultmutabletreenode swing = new defaultmutabletreenode("swing"); defaultmutabletreenode tr = new defaultmutabletreenode("tree"); defaultmutabletreenode = new defaultmutabletreenode("3½ floppy(a:)"); defaultmutabletreenode e = new defaultmutabletreenode("new volume(e:)"); c.add(vinod); vinod.add(swing); swing.add(tr); mycomputer.add(c); mycomputer.add(a); mycomputer.add(e); jtree tree = new jtree(mycomputer); jscrollpane scrollpane = new jscrollpane(tree); jpanel1.add(scrollpane); tree.setvisible(true);
i got new tree example web, when try show it, not appear! dont know why. ideas? thank you!
adjusted code sscce, works fine here
public static void main( string[] args ) { eventqueue.invokelater( new runnable() { @override public void run() { jframe frame = new jframe(); defaultmutabletreenode mycomputer = new defaultmutabletreenode("my computer"); defaultmutabletreenode c = new defaultmutabletreenode("local disk(c:)"); defaultmutabletreenode vinod = new defaultmutabletreenode("vinod"); defaultmutabletreenode swing = new defaultmutabletreenode("swing"); defaultmutabletreenode tr = new defaultmutabletreenode("tree"); defaultmutabletreenode = new defaultmutabletreenode("3½ floppy(a:)"); defaultmutabletreenode e = new defaultmutabletreenode("new volume(e:)"); c.add(vinod); vinod.add(swing); swing.add(tr); mycomputer.add(c); mycomputer.add(a); mycomputer.add(e); jtree tree = new jtree(mycomputer); jscrollpane scrollpane = new jscrollpane(tree); frame.getcontentpane().add(scrollpane); tree.setvisible(true); frame.setdefaultcloseoperation( windowconstants.exit_on_close ); frame.pack(); frame.setvisible( true ); } } ); }
Comments
Post a Comment