How to load a directory in JTree with Children(On expansion)

Hi,
How can I load a Jtree directory with children on expanding the node of that directory.
I have developed the following SSCCE. Please explain in its context.
My specific question is, when you execute the code given here, you can see the file bb.1 inside the directory bb.
bb.1 is a dummy which I used while creating the Jtree. When I expand bb, instead of the leaf bb.1 , I want to display some other file name, say qq.1 or jj.1.
What should I do?
Hope my question is clear(http://forums.sun.com/thread.jspa?threadID=5337544&start=20&tstart=0 -- please ignore the given link).
//FileTreeFrame.java
import java.util.ArrayList;
import java.util.List;
import javax.swing.JFrame;
import javax.swing.JTree;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeModel;
public class FileTreeFrame extends JFrame {
  private JTree fileTree;
  private FileSystemModel fileSystemModel;
  public FileTreeFrame(String abc) {
    super("JTree FileSystem Viewer");
    // Build up your data
    List rootChildren = new ArrayList();
    rootChildren.add( new MyNode("aa") );
    List bbChildren = new ArrayList();
    bbChildren.add( new MyNode("bb.1") );
    rootChildren.add( new MyNode("bb", bbChildren) );
    rootChildren.add( new MyNode("cc") );
    MyNode rootNode = new MyNode("root", rootChildren);
    fileTree = new JTree(new FileSystemModel(new MyTreeNode(rootNode)));
    fileTree.setRootVisible(false);
    fileTree.setShowsRootHandles(true);
    getContentPane().add(fileTree);
    setDefaultCloseOperation(EXIT_ON_CLOSE);
    setSize(640, 480);
    setVisible(true);
  public static void main(String args[]) {
    new FileTreeFrame("");
class FileSystemModel extends DefaultTreeModel {
    public FileSystemModel(DefaultMutableTreeNode node) {
          super(node);
    public boolean isLeaf(Object node) {
          MyTreeNode treeNode = (MyTreeNode)node;
          return !((MyNode)treeNode.getUserObject()).hasChildren();
=======================================================
//MyNode.java
import java.util.List;
public class MyNode {
      private String name;
      private List children;
      public MyNode(String name) {
            this.name = name;
      public MyNode(String name, List children) {
            this.name = name;
            this.children = children;
      public boolean hasChildren() {
            return children!=null && children.size()>0;
      public String toString() {
            return name;
      public List getChildren() {
            return children;
=========================================================
//MyTreeNode.java
import java.util.Iterator;
import javax.swing.tree.DefaultMutableTreeNode;
public class MyTreeNode extends DefaultMutableTreeNode {
    public MyTreeNode(MyNode node) {
        super(node);
        addSubNodes();
    private void addSubNodes() {
          MyNode content = (MyNode)getUserObject();
          if (content!=null && content.hasChildren()) {
                for (Iterator it = content.getChildren().iterator(); it.hasNext();) {
                      add( new MyTreeNode((MyNode)it.next()) );
}

I believe JFileChooser has a method setFileSelectionMode() which will allow you to do this. You can configure the chooser to allow selection of FILES_ONLY, DIRECTORIES_ONLY or FILES_AND_DIRECTORIES.
I have not used this myself but understand it will achieve what you need.

Similar Messages

  • [S] How to load another keymap in initramfs with busybox (loadkmap?)?

    Loading programmers dvorak in initramfs with busybox.
    Solution:
    Download the keyboard map. Other keyboard maps you can usually find in "/usr/share/kbd/keymaps/"
    wget https://raw.githubusercontent.com/jiangmiao/dvp/master/dvp.map
    Now convert that map to the binary format that can be used with `loadkmap`. Make sure you run it with privileges, otherwise you'll get the "Couldn't get a file descriptor referring to the console" error
    sudo loadkeys -b dvp.map > dvp.bmap
    Now you can load that map in initramfs using `loadkmap`. I have a custom initramfs and init and here is the excerpt from it
    #!/usr/bin/ash
    echo "Starting the init script"
    #mount things needed by this script
    mount -t proc proc /proc
    mount -t sysfs sysfs /sys
    # and so on
    echo "creating the symlinks to busybox"
    /bin/busybox --install -s
    echo "loading programmers dvorak"
    loadkmap < dvp.bmap
    Problem
    I have a custom initramfs with Busybox in it. I want to load another keymap in there. Busybox has `loadkmap` utility, unfortunately it expects a binary file, so .map files don't fit in there. The goal is to load programmer's dvorak in busybox, but the problem is generic, because any ANSI .map format will not work with `loadkmap`.
    The map for dvp is here: https://github.com/jiangmiao/dvp
    Here it was talked about, but unfortunately the patch link is dead: http://mstempin.free.fr/index.php?2005/ … ry-keymaps
    How to load a keymap in initramfs with busybox?
    FTR, here is the quote from that blog post
    Unfortunately, This is not a trivial task in Busybox, as it uses a special binary keymap file format for specifying the keymap to use.
    The standard Linux way of handling keymaps is using the kbd utility package. This package contains most of the worldwide keyboard definitions in a keymap format. The two most usefull commands are the loadkeys and dumpkeys, which respectively loads an ASCII keymap file into the kernel's internal translation table and dumps this table to the standard output.
    Unfortunately, the keymaps file format (see Linux manual (5) for keymaps) is difficult to parse ,as it requires a full lex/yacc parser to handle it :-(.
    However, such a parser is included into loadkeys... And this utility also provides a -m option that generates a C-style output of the file...
    After studying Busybox's binary keymap format in details, it appears to be no more than just a file dump of all key translation tables for each state (ie. plain, shifted, controlled, etc.), preceeded by a binary map of translation tables.
    So, I decided to write a patch to the kbd package to add a -b option that provides a binary keymap dump capability to loadkeys. Here it is!
    Last edited by SteveSapolsky (2014-12-19 12:39:13)

    progandy wrote:
    In archlinux loadkeys from core/kbd should allow you to generate a binary keymap.
    loadkeys -b /your/key.map > key.bmap
    Thank you. I updated my post and added the solution.

  • How to get correct node in JTree with DISCONTIGUOUS_TREE_SELECTION mode?

    The following code creats a JTree with DISCONTIGUOUS_TREE_SELECTION mode. When select a single node, the node's name is printed correctly as expected. However, in Window environment, after select one node, if holding the ctrl key and select a different node, the program still prints out the name of the first selected node although both nodes are highlighted. Can some one tell me how to get the name of the second (i.e. the last) selected node printed?
    Thank you very much!
    import javax.swing.*;
    import javax.swing.tree.*;
    import javax.swing.event.*;
    import java.io.*;
    public class TestTree extends JFrame {
    JTree tree;
    public TestTree() {
    super();
    setBounds(0,0,500,500);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    tree = new JTree();
    getContentPane().add(tree);
    TreeSelectionModel model = new DefaultTreeSelectionModel();
    model.setSelectionMode(TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION);
    tree.setSelectionModel(model);
    tree.addTreeSelectionListener(new TreeSelectionListener() {
    public void valueChanged(TreeSelectionEvent e) {
    Object obj = tree.getLastSelectedPathComponent();
    System.out.println(obj.toString());
    public static void main(String [] args) {
    TestTree test = new TestTree();
    test.show();

    Hi!
    Try this, maybe it's what you want?
    /Smedman
    public void valueChanged(TreeSelectionEvent e)
        TreePath[] paths = tree.getSelectionPaths();
        for (int i = 0; i < paths.length; i++)
            System.out.println(paths.getLastPathComponent());

  • How to load and unload same SWF with different xmlFilePath?

    I have a slideshow on my homepage and try to load and unload same instance with different xmlFilePath based on language on the same page.
    var flashvars = {
            xmlFilePath: escape("http://www.bodto.com.tr/kik.aspx"),
            xmlFileType: "OPML",
            lang: swfobject.getQueryParamValue("lang")    
            //initialURL: escape(document.location)   
          var params = {
            bgcolor: "#000000",  
            allowfullscreen: "true",
            wmode:"transparent",
            allowScriptAccess: "always"
          var attributes = {}
              swfobject.embedSWF("/swf/slideshowpro.swf", "flashcontent", "550", "400", "10.0.0", false, flashvars, params, attributes);
    Actionscript3
    var langPath = root.LoaderInfo.parameters["xmlFilePath"]+root.LoaderInfo.parameters["lang"];
    my_ssp.xmlFilePath = langPath;
    var fileType = root.LoaderInfo.parameters["xmlFileType"];
    my_ssp.xmlFileType = fileType;
    Based on above informations, how could I achieve it?

    Suddenly that code in the following gives me some error
    var langPath = root.LoaderInfo.parameters["xmlFilePath"]+root.LoaderInfo.parameters["lang"];
    my_ssp.xmlFilePath = langPath;
    var fileType = root.LoaderInfo.parameters["xmlFileType"];
    my_ssp.xmlFileType = fileType;
    Access of possibly undefined property LoaderInfo through a reference with static type flash.display:DisplayObject.
    The only code snippet works is
    var paramObj:Object = LoaderInfo(this.root.loaderInfo).parameters;
    for (var param in paramObj) {
       if (param == "xmlFilePath") {
          my_ssp.xmlFilePath = paramObj[param];
       if (param == "xmlFileType") {
          my_ssp.xmlFileType = paramObj[param];

  • How to load CD's on Netbook with no CD drive

    My wife just got a iPod shuffle. I installed iTunes on her Dell Netbook running Windows XP but can't figure out how to load her CD's since it doesn't have a CD drive. I've shared the CD on my laptop but it does not seem to expose it properly for either playing or copying.
    What are my options?
    Thanks

    put them on a removable hard drive or thumb drive and transfer the that way, as data.

  • How to load a movieclip from libary with a button?

    Hi!
    I am kinda new to Flash and i have a queston.I made a
    movieclip that i keep in the libary. I have a button that i want to
    load the movieclip on the screen while pressing it. Queston is: how
    or what kind of code do i put for the button to load the movieclip
    wich is in my libary? As i see there is no simple soulution for
    this with the script assistent? I got the option load movie but it
    only loads external files or i get error messages when trying to
    load my movie.
    Please help me with this.
    /Tobias

    there are a few things you'll need to do in order to achieve
    this, but it's not to complicated. First right-click the MC in the
    Library and select 'properties', then in the 'Linkage' section
    select the check box 'Export for ActionScript' and the type a name
    in the 'Identifier' field, hit OK. now you can access the MC by the
    linkage ID.
    the next thing you will need to know is 'where' you want to
    place the MC, figure out the x,y position. then on the main
    timeline, handle the 'button' code and we'll use 'attachMovie' to
    bring the MC to the Stage. within the attachMovie method we'll also
    pass the position you've decided upon. so it would look something
    like this:

  • How to load compressed tiff image formats with JIMI

    this method
    Image image=image = Jimi.getImage(imgResource);returns incorrect Image width & height (-1) for TIFF compressed formats.
    is there any jimi example showing how to properly load the tiff compressed image ?
    thanks.

    Wild guess: how old is JIMI technology? Has it been
    kept uptodate, or has
    it been abandoned? And is LZW compression in TIFF
    format a more recent feature?yes i checked jimi docs and here is what they say :
    TIFF      
    * Bi-level / Greyscale / Palette / True Color images
    * Uncompressed images
    * CCITT compressed Bi-level images with CCITT RLE, CCITT Group 3 1D Fax, CCITT Group 3 2D Fax, CCITT Group 4 Fax, CCITT Class F Fax
    * Packbits compressed images
    * LZW Compressed images
    * Tiled TIFF files
    * Handles all values of Orientation
    * TIFF / JPG compression variant
    * any color space except RGB
    * True Color images not of Red/Green/Blue format

  • Does anyone know how to load a skin . swf file with video to dreamweaver

    I have input the video into flash cs3 and then used the
    properties section for adding the video in the source section. I
    then put the skin with the first drop down. I saved and just put it
    in dreamweaver however does not work.. I was told the skin may not
    have be sent automatically. How do we do this. Get the skin . swf
    file to go with the video or get them both into dreamweaver. I does
    not show up on my site.
    Site. www.tesoromp3.com
    thank phol

    I haven't seen too many questions like this on this forum.  Did you also try the photoshop forums?

  • How to load turbotax on mac air with usb super drive

    i am trying to load turbo tax and cant get it to install.  i have a mac air and a usb superdrive. 

    I have TurboTax 2012 and have done it.  First, plug the SuperDrive into your USB port.  Then insert the TurboTax CD into the drive.  You will see the TurboTax icon and a folder icon representing your application folder on your desktop.  SImply drag the TurboTax icon over on top of the folder icon (as the arrow represents), let the action complete, and you will be done installing TurboTax!
    Finally, remember to eject the TurboTax disk from the SuperDrive before unplugging the drive from your USB port.  Depending on how you have Finder set up, you may have to hunt for the drive's icon.  It may be in Finder's sidebar.

  • CSS - How to Load a script

    hello,
    I wonder if anybody can explain how to load a script to run with CSS 11050.
    many thanks
    Raquel

    Hi Raquel,
    Do you mean a custom script or one of the canned scripts that ship with the CSS ?
    If you want to load a custom script file, simply ftp to the CSS.
    Once connected to the CSS via FTP (you will be in the running code directory when you ftp into any CSS), CD to "script". Once in this directory, you can "put" the file into the directory. Do not use any file extensions here.
    Now, from the CSS cli, you can do a "script play filename" where filename is the name of your script. If you want to see what scripts are there (to see if your file is there correctly), do a "script play ?"
    If you need further direction, feel free to reply here. You can also have a look at the following link:
    http://www.cisco.com/univercd/cc/td/doc/product/webscale/css/css_500/advcfggd/appa.htm
    Regards
    Pete Knoops
    Cisco Systems

  • How do share an apple ID with children but have them not get your e-mail???

    How do I share an apple ID with children on other ios's but have them not get my e-mail??

    You can't. Access to your Apple ID gives them access to all of your iCloud account, not just part of it.

  • How to use Jtree to load some directory?

    Hello everyone, I need use JTree to show the whole files and directories from some one directory(such as C:/test/javademo), so could you please give me some
    idea about that, thanks a million.
    Yours Leon

    I actually think recursion is a bad idea - why load all the subfolders and files into the tree recursively at the beginning? This will just take more time and disk access (think slow) which is unneeded. Below is the tutorial to write a JTree with a treeWillExpand listener. What you'll want to do is have it init a root DefaultMutableTreeNode to whatever folder you want it to begin at. Then you'll add children to that DefaultMutableTreeNode to represent the folder's contents (files and folders). At the point where the user wishes to expand a directory, the TreeWillExpand method will be called, you can get the path of DefaultMutableTreeNodes and use that to reference into the disk to load up the folder's children.
    I probably made that more complex sounding than it needed to be. Check out this sun tutorial and code examples:
    http://java.sun.com/docs/books/tutorial/uiswing/events/treewillexpandlistener.html

  • How to populate a sharepoint 2010 list from the active directory. How to populate a sharepoint 2010 list with all sharepoint user profiles

    How to populate a sharepoint 2010 from the active directory.
    I want a list of all the computers in the active directory,
    another one with all users.
    I want also to populate a sharepoint 2010 list from the sharepoint user profiles.
    Thanks
    sz

    While
    the contacts list is usually filled out for contacts that are outside the company, there are times when you would use a contacts list to store internal and external resources.  Wouldn’t it be nice if you didn’t have to re-type your internal contacts’
    information that are already in the system?  Now you can with a little InfoPath customization on the contacts list. 
    Here’s our plan:
    Create the contacts list, and open in InfoPath
    Create a data connection to the User Profile web service
    Customize the form adding some text, a people picker and a button
    Create InfoPath rules that will populate the contact fields from the user fields in the User Profile store
    Let’s get going!  Before we begin, make sure you have InfoPath 2010 installed locally on your computer.  I also want to give credit Laura
    Rogers and Darvish Shadravan’s book Using
    Microsoft InfoPath 2010 with Microsoft SharePoint 2010 Step by Step.  I know it looks like a lot of steps, but it’s easy once you get the hang of it.
    So obviously we need a contacts list.  If you don’t already have one, go to the SharePoint site where it will live, and create a contacts list.
    From the list, click the List tab on the ribbon, then click Customize form:
    So now we have our form open in InfoPath 2010.  Let’s add our elements to the form. 
    Above all the fields, let’s add some text instructing users what to do with the the field we’re about to add (.e.g To enter an existing user’s information, choose the user below).
    Insert a people picker control by clicking the Person/Group Picker control in the Controls section of the ribbon.  This will add a column to the contacts list called group.
    Below the people picker, insert a button control from the same section of the ribbon as above.  With the button still highlighted, click the Control Tools|Properties tab on the ribbon. 
    Then in the Label box, change the text to something more appropriate to our task (e.g. Click here to load user data!).
    You can drag the button control a little larger to account for the text.
    We should end up with something like this:
    Before we can populate the fields with user data, we need to create a connection to the User Profile Service.
    Add a data connection to the User Profile Service
    Click the Data tab on the ribbon, and click the option From Web Service, and From SOAP Web Service.
    For the location, enter the URL of your SharePoint site in the following format – http://<site url>/_vti_bin/UserProfileService.asmx?WSDL.  Click Next.
    Note - for the URL, it can be any SharePoint site URL, not just to the site where your list is.
    For the operation, choose GetUserProfileByName.  Click Next.
    Click Next on the next two screens.
    On the final screen, uncheck the box for “Automatically retrieve data when form is opened”. This is because we are going to retrieve the data when the button is clicked, also for performance reasons.
    Now we need to wire up the actions on our button to populate the fields with the information for the user in the people picker control.
    Tell the form to read the user from the people picker control
    Click the Home tab on the ribbon.
    Click the button control we created, and under the Rules section of the ribbon, click Manage Rules. Notice the pane appear on the far right.
    In the Rules pane, click New –> Action. Change the name to something like “Query and load user data”.
    Leave the condition to default (none – rule runs when button is clicked).
    Click the Add button next to “Run these actions:”, and choose “Set a field’s value”.
    For Field, click the button on the right to load the select a field dialog.  Click the Show advanced view on the bottom.  At the top, click the drop down and choose the GetUserProfileByName
    (Secondary) option.  Expand myFields and queryFields to the last option and highlightAccountName.  Click ok. 
    For Value, click the formula icon. On the formula screen, click the Insert Field or Group button. Again click the show advanced view link, but this time leave the data
    connection as Main. Expand dataFields, then mySharePointListItem_RW.  At the bottom you should see a folder called group (the people picker control we just added to the form).  Expand this, then pc:Person,
    and highlightAccountId.  Click Ok twice to get back to the Rules pane.
    If we didn’t do this and just queried the user profile service, it would load the data of the currently logged in user.  So we need to tell the form what user to load the data for.  We take the AccountID field from the people
    picker control and inject into the AccountName query field of the User Profile Service data connection. 
    Load the user profile service information for the chosen user
    Click the Add button next to “Run these actions:”, and choose Query for data.
    In the popup, for Data connection, click the one we created earlier – GetUserProfileByName and clickOk.
    We’re closing in on our goal.  Let’s see our progress.  We should see something like this:
    Now that we have the user’s data read into the form, we can populate the fields in the contact form.  The number of steps to complete will depend on how many fields you want to populate.  We need to add an action step for
    each field.  I’ll show you one example and then you will just repeat the steps for the other fields.  Let’s update the Job Title field.
    Populate the contact form fields with existing user’s data
    Click the Add button next to “Run these actions:”, and choose “Set a field’s value”.
    For Field, click the button on the right to load the select a field dialog.  Highlight the field Job Title.
    For Value, click the formula icon. On the formula screen, click the Insert Field or Group button.  Click the Show advanced view on the bottom. At the top, click the
    drop down and choose theGetUserProfileByName (Secondary) option.  Expand the fields all the way down until you see the Value field.  Highlight it but don’t click ok, but click the Filter
    Data button, then Add. 
    For the first dropdown that says Value, choose Select a field or group.   The value field will be highlighted, but click the field Name field
    under PropertyData.  Click Ok. 
    In the blank field after “is equal to”, click in the box and choose Type text.  Then type the text Title. 
    Click ok until you get back to the Manage Rules pane.  The last previous screen will look like this.
    We’re going to update common fields that are in the user’s profile, and likely from Active Directory.  You can update fields like first and last name, company, mobile and work phone number, etc.  For the other fields, the
    steps are the same except the Field you choose to update from the form, and the very last step where you enter the text will change.  Here’s what the rules look like when we’re done:
    We’re all done, good work!  You can preview the form and try it now.  Click Ctrl+Shift+B to preview the form.  Once you’re satisfied, you can publish the form back to the library.  Click File –> Quick
    Publish.  Once it’s done, you will get confirmation:
    Now open your form in SharePoint.  From the contact list, click Add new item.  Type in a name, and click the button and watch the magic happen!

  • Sunday, I downloaded iTunes app on to my new PC.  Songs purchased over the years were present but all of the albums I loaded from CD's are not present.  How do I resore my iTunes account with all of my albums, playlists, etc.?

    Sunday, I downloaded iTunes app on to my new PC.  Songs purchased over the years were present but all of the albums I loaded from CD's are not present.  How do I resore my iTunes account with all of my albums, playlists, etc.?  I have not attempted to sysnch my IPod Nano with the new software.

    See Empty/corrupt iTunes library after upgrade/crash.
    tt2

  • How to load a image after getting it with a file chooser?

    I'm still starting with JavaFX, and I simply would like to know how to load the image (e.g. png or jpg) that I selected using a FileChooser in the user interface. I can access the file normally within the code, but I'm still lost about how to load it appropriately. Every time I select a new image using the FileChooser, I should discard the previous one and consider the new one. My code is shown below:
    import javafx.stage.Stage;
    import javafx.scene.Scene;
    import javafx.scene.shape.Rectangle;
    import javafx.scene.paint.Color;
    import javafx.scene.layout.HBox;
    import javafx.scene.control.Button;
    import javax.swing.JFileChooser;
    import javafx.scene.image.ImageView;
    import javafx.scene.image.Image;
    var chooser: JFileChooser = new JFileChooser();
    var image;
    Stage {
        title: "Image"
        scene: Scene {
            width: 950
            height: 500
            content: [
                HBox {
                    layoutX: 670
                    layoutY: 18
                    spacing: 10
                    content: [
                        Button {
                            text: "Open"
                            action: function() {
                                if (JFileChooser.APPROVE_OPTION == chooser.showOpenDialog(null)) {
                                    var imageFile = chooser.getSelectedFile();
                                    println("{imageFile.getCanonicalFile()}");
                                    image = Image{
                                        width: 640
                                        url:imageFile.getAbsolutePath()
                // Image area
                Rectangle {
                    x: 10
                    y: 10
                    width: 640
                    height: 480
                    fill: Color.WHITE
                ImageView {
                    x: 10
                    y: 10
                    image: bind image
    }Thank you in advance for any suggestion to make it work. :)

    As its name implies, the url param expect... an URL, not a file path!
    So, use {color:#8000FF}url: imageFile.toURI().toURL(){color} instead.

Maybe you are looking for

  • How can I see usage statistics on my podcast?

    I would also like to change the email address associated with the podcast (created in 2007 and we've changed personnel since then) but that's secondary. My main question is where can I go to see how much activity we're receiving on my podcast via iTu

  • How to recover administrator password in windows 7 using usb

    I have an HP netbook mini and need to how to recover administrator password in windows 7 using usb as we have forgotten and need to load itunes from another Iphone. This question was solved. View Solution.

  • Any way to increase HD capacity on the iMAC?

    Is there any way to upgrade the internal HD on the iMAC to say about 500GB and transfer all data from the installed drive? Thanks. Dave Wilson

  • Depoying web service in oracle weblogic from jdeveloper 10.

    hi , i implement a web service and i deploy it in oracle weblogic from Jdeveloper 10. but when testing this web service, it evaluates them as null. and the wsdl in jdevelpor has 8888 not 7001. please someone help me. thank you aymen

  • How do I convert file to gif, jpg, jpeg, png, bmp, or swf

    I mad a page in COMIC LIFE. I saved it, then when i went on photobucket.com, it gave me a message saying The file "" does not have a valid image extension. Valid image extensions are: gif, jpg, jpeg, png, bmp, swf. HOW DO I CHANGE IT? Thanks