java - JTree create new file make it selected -


I want to make it like when I click on a button, it will create a new file. Then jTree will highlight the new file. Below is my code. Currently I create new file, I will show new file but no charity file

class fileTreeModel applies TreeModel {Private FileNode root. Public FileTreeModel (string directory) {root = new FileNode (directory); } Public Object getRoot () {Return Route; } Public object getChild (object parent, int index) {FileNode parentNode = (FileNode) parent; Return to the new file node (parentNode, parentNode.listFiles () [index] .getName ()); } Public int biltscount (object parent) {FileNode parentNode = (FileNode) Parent; If (parent == infirm ||! ParentNode.isDirectory () || parentNode.listFiles () == faucet) {return 0; } Return parentNode.listFiles (). Length; } Is a public boolean, leaf (object node) {return (matching delimiter (node) == 0); } Public int getIndexOfChild (object parent, object child) {FileNode parentNode = (FileNode) parent; FileNode childNode = (FileNode) child; Return arrays.asList (parentNode.list ()). IndexOf (childNode.getName ()); } Public Zero valueForPathChanged (TreePath path, object newValue) {} Public Zero addTreeModelListener (TreeModelListener L) {} Public Zero removeTreeModelListener (TreeModelListener L) {}

}

  class FileNode extends java.io.file {public FileNode (string directory) {super (directory); } Public FileNode (FileNode Basic, String Child) {Super (parent, child); } @ Override public string to string () {return getName (); }  

}

  jTree = new JTree (); JTree.setBounds (new rectangle (164, 66, 180, 421)); JTree.setBackground (SystemColor.inactiveCaptionBorder); JTree.setBorder (BorderFactory.createTitledBorder ("zero", "title", "Border.LEADING", title "Border.TOP", new font ("Arial", font. BA, 12), new color (0, 0, 0) )); File tree model model = new file tree model (route); JTree.setRootVisible (wrong); JTree.setModel (model); ExpandAll (jTree); Public Zero Extensions All (Jatri Trees) {int row = 0; While (line & lt; tree.getRowCount ()) {tree.expandRow (line); Line ++; }}  

You can do this by calling;


Comments

Popular posts from this blog

windows - Heroku throws SQLITE3 Read only exception -

lex - Building a lexical Analyzer in Java -

python - rename keys in a dictionary -