How can Display a specified sub set of a Jtree??

Dear Friends: Good weekends:
I have following code:
import javax.swing.*;
import javax.swing.tree.*;
import apl.jhu.edu.JTree.ExitListener;
import apl.jhu.edu.JTree.WindowUtilities;
import java.awt.*;
     public class JTreeCars  extends JFrame {
       DefaultTreeModel treeModel;
       public JTreeCars() {
         super("Editable Tree Frame");
            JTreeSub js = new JTreeSub();
         setSize(200, 200);
         WindowUtilities.setNativeLookAndFeel();
         addWindowListener(new ExitListener());
         setDefaultCloseOperation(EXIT_ON_CLOSE);
       public class JTreeSub  extends JTree {
            public JTreeSub() {
            super();
            init();
       public void init(){
         DefaultMutableTreeNode Manufacturers = new DefaultMutableTreeNode("Car Makers");
         DefaultMutableTreeNode Cars = new DefaultMutableTreeNode("Cars");
         DefaultMutableTreeNode Nissan = new DefaultMutableTreeNode("Nissan");
         DefaultMutableTreeNode Nissan90 = new DefaultMutableTreeNode("Nissan90");
         DefaultMutableTreeNode Nissan91 = new DefaultMutableTreeNode("Nissan91");
         DefaultMutableTreeNode Nissan92 = new DefaultMutableTreeNode("Nissan92");
         DefaultMutableTreeNode Nissan95 = new DefaultMutableTreeNode("Nissan95");
         DefaultMutableTreeNode Nissan98 = new DefaultMutableTreeNode("Nissan98");
         DefaultMutableTreeNode Nissan2001 = new DefaultMutableTreeNode("Nissan2001");
         DefaultMutableTreeNode Nissan2002 = new DefaultMutableTreeNode("Nissan2002");
         DefaultMutableTreeNode Nissan2003 = new DefaultMutableTreeNode("Nissan2003");
         DefaultMutableTreeNode Nissan99 = new DefaultMutableTreeNode("Nissan99");
              Nissan.add(Nissan90);
              Nissan.add(Nissan91);
              Nissan.add(Nissan92);
              Nissan.add(Nissan95);
              Nissan.add(Nissan98);
              Nissan.add(Nissan99);
              Nissan.add(Nissan2001);
              Nissan.add(Nissan2002);
              Nissan.add(Nissan2003);
         DefaultMutableTreeNode Ford = new DefaultMutableTreeNode("Ford");
         DefaultMutableTreeNode Ford2001 = new DefaultMutableTreeNode("Ford2001");
         DefaultMutableTreeNode Ford2002 = new DefaultMutableTreeNode("Ford2002");
         DefaultMutableTreeNode Ford2003 = new DefaultMutableTreeNode("Ford2003");
         DefaultMutableTreeNode Ford2004 = new DefaultMutableTreeNode("Ford2004");
         DefaultMutableTreeNode Ford2005 = new DefaultMutableTreeNode("Ford2005");
              Ford.add(Ford2001);
              Ford.add(Ford2002);
              Ford.add(Ford2003);
              Ford.add(Ford2004);
              Ford.add(Ford2005);
         DefaultMutableTreeNode Benz = new DefaultMutableTreeNode("Benz");
         DefaultMutableTreeNode Benz81 = new DefaultMutableTreeNode("Benz81");
         DefaultMutableTreeNode Benz82 = new DefaultMutableTreeNode("Benz82");
         DefaultMutableTreeNode Benz83 = new DefaultMutableTreeNode("Benz83");
         DefaultMutableTreeNode Benz84 = new DefaultMutableTreeNode("Benz84");
         DefaultMutableTreeNode Benz85 = new DefaultMutableTreeNode("Benz85");
         DefaultMutableTreeNode Benz2001 = new DefaultMutableTreeNode("Benz2001");
         DefaultMutableTreeNode Benz2002 = new DefaultMutableTreeNode("Benz2002");
         DefaultMutableTreeNode Benz2003 = new DefaultMutableTreeNode("Benz2003");
              Benz.add(Benz81);
              Benz.add(Benz82);
              Benz.add(Benz83);
              Benz.add(Benz84);
              Benz.add(Benz85);
              Benz.add(Benz2001);
              Benz.add(Benz2002);
              Benz.add(Benz2003);
         DefaultMutableTreeNode Toyota = new DefaultMutableTreeNode("Toyota");
         DefaultMutableTreeNode Cherry = new DefaultMutableTreeNode("Cherry");
         treeModel = new DefaultTreeModel(Manufacturers);
         JTree tree = new JTree(treeModel);
         tree.setEditable(true);
         treeModel.insertNodeInto(Cars,Manufacturers, 0);
         Cars.add(Nissan);
         Cars.add(Ford);
         Cars.add(Benz);
         Cars.add(Toyota);
         Cars.add(Cherry);
         getContentPane().add(tree, BorderLayout.CENTER);
       public static void main(String args[]) {
            JTreeCars st = new JTreeCars();
            st.setVisible(true);
     }I only hope to display subset of this whole JTree, ie, the Nodes with 2001, 2002, 2003 will be displayed, all others will be hidden, not to display
Here I hope only the node contains "2001" , "2002", "2003" will be displayed. all others will not be displayed.
Please advice how to do it??
Thanks a nd have a good weekends.
sunny

Thanks Michael,
I just post my updated code, I hope if I uncheck the box, all tree will be displayed, if I check it, Only 2001,2002, 2003 cars show up, looks like my code not work, what is wrong here??
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeModel;
import javax.swing.tree.TreeNode;
class FilterTreeModel extends DefaultTreeModel {
       Filter filter;
       String sText;
       public FilterTreeModel(TreeNode root, Filter filter) {
         super(root);
         this.filter =filter;
       public void setFiltered(boolean pass, String sstr) {
         filter.setFiltered(pass,sstr );
         sText=sstr;
         Object[] path = {root};
         int[] childIndices  = new int[root.getChildCount()];     
         Object[] children  = new Object[root.getChildCount()];
         for (int i = 0; i < root.getChildCount(); i++) {
           childIndices[i] = i;
           children[i] = root.getChildAt(i);
         fireTreeStructureChanged(this,path,childIndices, children);
       public int getChildCount(Object parent) {
         int realCount = super.getChildCount(parent), filterCount=0;
         for (int i=0; i<realCount; i++) {
           DefaultMutableTreeNode dmtn = (DefaultMutableTreeNode)super.getChild(parent,i);
           if (filter.pass(dmtn, sText)) filterCount++;
         return filterCount;
       public Object getChild(Object parent, int index) {
         int cnt=-1;
         for (int i=0; i<super.getChildCount(parent); i++) {
           Object child = super.getChild(parent,i);
           if (filter.pass(child,sText)) cnt++;
           if (cnt==index) return child;
         return null;
     interface Filter {
       public boolean pass(Object obj, String stt);
       public void setFiltered(boolean pass, String str);
       public boolean isFiltered();
     class MyFilter implements Filter {
       boolean pass=true;
       String  strFilter;
       public boolean pass(Object obj, String sttr) {
         if (pass) return true;
         //char c = obj.toString().charAt(0);
         String c = obj.toString();
        // return Character.toLowerCase(c)<0;
         return c.contains(sttr);
       public void setFiltered(boolean pass, String str) {
            this.pass=pass;
            strFilter= str;
       public boolean isFiltered() {
            return pass;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.tree.*;
public class JTreeCarDemo extends JFrame {
  JTreeSub jt = new JTreeSub();
  MyFilter mf = new MyFilter();
  JCheckBox jcb = new JCheckBox("Filter");
  FilterTreeModel ftm = new FilterTreeModel((TreeNode)jt.getModel().getRoot(), mf);
  DefaultTreeModel treeModel;
  public JTreeCarDemo() {
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    Container content = getContentPane();
    jt.setModel(ftm);
    content.add(new JScrollPane(jt), BorderLayout.CENTER);
    content.add(jcb, BorderLayout.SOUTH);
    jcb.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent ae) {
        ftm.setFiltered(!jcb.isSelected(), "200");
    setSize(500, 700);
    setVisible(true);
    setTitle("New Car from 2000");
  public static void main(String[] args) {
       new JTreeCarDemo();
  public class JTreeSub  extends JTree {
       public JTreeSub() {
       super();
         DefaultMutableTreeNode Manufacturers = new DefaultMutableTreeNode("Car Makers");
         DefaultMutableTreeNode Cars = new DefaultMutableTreeNode("Cars");
         DefaultMutableTreeNode Nissan = new DefaultMutableTreeNode("Nissan");
         DefaultMutableTreeNode Nissan90 = new DefaultMutableTreeNode("Nissan90");
         DefaultMutableTreeNode Nissan91 = new DefaultMutableTreeNode("Nissan91");
         DefaultMutableTreeNode Nissan92 = new DefaultMutableTreeNode("Nissan92");
         DefaultMutableTreeNode Nissan95 = new DefaultMutableTreeNode("Nissan95");
         DefaultMutableTreeNode Nissan98 = new DefaultMutableTreeNode("Nissan98");
         DefaultMutableTreeNode Nissan2001 = new DefaultMutableTreeNode("Nissan2001");
         DefaultMutableTreeNode Nissan2002 = new DefaultMutableTreeNode("Nissan2002");
         DefaultMutableTreeNode Nissan2003 = new DefaultMutableTreeNode("Nissan2003");
         DefaultMutableTreeNode Nissan99 = new DefaultMutableTreeNode("Nissan99");
         Nissan.add(Nissan90);
         Nissan.add(Nissan91);
         Nissan.add(Nissan92);
         Nissan.add(Nissan95);
         Nissan.add(Nissan98);
         Nissan.add(Nissan99);
         Nissan.add(Nissan2001);
         Nissan.add(Nissan2002);
         Nissan.add(Nissan2003);
    DefaultMutableTreeNode Ford = new DefaultMutableTreeNode("Ford");
    DefaultMutableTreeNode Ford2001 = new DefaultMutableTreeNode("Ford2001");
    DefaultMutableTreeNode Ford2002 = new DefaultMutableTreeNode("Ford2002");
    DefaultMutableTreeNode Ford2003 = new DefaultMutableTreeNode("Ford2003");
    DefaultMutableTreeNode Ford2004 = new DefaultMutableTreeNode("Ford2004");
    DefaultMutableTreeNode Ford2005 = new DefaultMutableTreeNode("Ford2005");
         Ford.add(Ford2001);
         Ford.add(Ford2002);
         Ford.add(Ford2003);
         Ford.add(Ford2004);
         Ford.add(Ford2005);
    DefaultMutableTreeNode Benz = new DefaultMutableTreeNode("Benz");
    DefaultMutableTreeNode Benz81 = new DefaultMutableTreeNode("Benz81");
    DefaultMutableTreeNode Benz82 = new DefaultMutableTreeNode("Benz82");
    DefaultMutableTreeNode Benz83 = new DefaultMutableTreeNode("Benz83");
    DefaultMutableTreeNode Benz84 = new DefaultMutableTreeNode("Benz84");
    DefaultMutableTreeNode Benz85 = new DefaultMutableTreeNode("Benz85");
    DefaultMutableTreeNode Benz2001 = new DefaultMutableTreeNode("Benz2001");
    DefaultMutableTreeNode Benz2002 = new DefaultMutableTreeNode("Benz2002");
    DefaultMutableTreeNode Benz2003 = new DefaultMutableTreeNode("Benz2003");
         Benz.add(Benz81);
         Benz.add(Benz82);
         Benz.add(Benz83);
         Benz.add(Benz84);
         Benz.add(Benz85);
         Benz.add(Benz2001);
         Benz.add(Benz2002);
         Benz.add(Benz2003);
    DefaultMutableTreeNode Toyota = new DefaultMutableTreeNode("Toyota");
    DefaultMutableTreeNode Cherry = new DefaultMutableTreeNode("Cherry");
    treeModel = new DefaultTreeModel(Manufacturers);
    JTree tree = new JTree(treeModel);
    tree.setEditable(true);
    //treeModel.insertNodeInto(Cars,Manufacturers, 0);
    Manufacturers.add(Cars);
    Cars.add(Nissan);
    Cars.add(Ford);
    Cars.add(Benz);
    Cars.add(Toyota);
    Cars.add(Cherry);
    getContentPane().add(tree, BorderLayout.CENTER);
}

Similar Messages

  • HT3349 How do you select a sub-set of cells from the entire document so you can print only those specific cells?

    How do you select a sub-set of cells from the entire document so you can print only those specific cells?

    There is no analog to MS Excels print range.  So the next best thing is to plan your data so that you don't need to use print range.  The next best thing after that is to select the range of cells you want to print, then copy, the switch to the application Preview, and create a new document from the clipboard (select the menu item "File > New from Clibboard") then select all, copy then paste to the destination (maybe an email) .
    You can also paste that portion of the table into another table (or a new table) by pasting values only

  • How can I get the sub folders in room structure?

    Hi guys,
    I have a quesion: in KM-Collaboration-roomstructure, if I have a folder A, how can I get its sub folders like A.1,A.1.1,A2.
    I mean of course  how code can realize: using context folder=(IPcdContext) ictx.loopup(path) ?
    Please give me some hint!
    Thanks so much!
    Regards,
    Liying

    The phone number format as well as the date language and format and the time format are controlled by the Region Format setting. Go to Settings > General >International > Region Format.  When you change a region format, you can go back one page (to International) and see an example of the date/time/phone number format that your selected region format will produce.

  • How can we assign one attribute set to multiple business partners at a time ?

    How can we assign one attribute set to multiple business partners at a time ? Is it possible ? Can anyone explain me ?

    Hello,
    please refer to the following thread:
    How can we assign one Attribute Set to multiple Business Partners at a time? Is it possible?
    best regards,
    Johannes

  • How can I create a sub-iTunes account for a teen?

    how can I create a sub-iTunes account for a teen?
    I need to separate our music libraries but still keep it under control from the main account (mine).

    iOS 5 & iCloud Tips: Sharing an Apple ID With Your Family

  • How can I change a song setting that is protected

    How can I change a song setting that is protected

    Dj-Rod wrote:
    How can I change a song setting that is protected
    If the song is indicating a "Kind" of "Protected AAC," that is not a setting.  It is an indication that the file contains Digital Rights Management (DRM).  DRM cannot be removed through normal conversion processes.

  • How can I create a sub-folder within my "Documents" folder?

    How can I create a sub-folder within my "Documents" folder? I have many similar documents that I want to group together. This will also un-clutter my Documents folder.

    Also, you can add a New Folder button to the Finder's toolbar by opening Finder, going to the View menu in the menubar, selecting Customize Toolbar..., and dragging the New Folder icon to the toolbar in the Finder window. Then it's just one-click for new folders wherever you want them.

  • I forgot my security questions and I have a different email address but it's not updated to my Apple ID how can I change my security setting and how to rescue my Apple ID?

    I forgot my security questions and I have a different email address but it's not updated to my Apple ID how can I change my security setting and how to rescue my Apple ID?

    Alternatives for Help Resetting Security Questions and Rescue Mail
         1. Apple ID- All about Apple ID security questions.
         2. Rescue email address and how to reset Apple ID security questions
         3. Apple ID- Contacting Apple for help with Apple ID account security.
         4. Fill out and submit this form. Select the topic, Account Security.
         5.  Call Apple Customer Service: Contacting Apple for support in your
              country and ask to speak to Account Security.
    How to Manage your Apple ID: Manage My Apple ID

  • Apple ID.  My newly updated iPad 2 wants an email for the apple ID.  My apple ID is not an email address.  How can I get past the set-up screen?

    My newly updated iPad 2 wants an email for the apple ID.  My apple ID is not an email address.  How can I get past the set-up screen?
    I can't change my Apple ID.  It would mess all my stuff up.

    To change the iCloud ID you have to go to Settings>iCloud, tap Delete Account, provide the password for the old ID when prompted to turn off Find My iPhone (if you're using iOS 7), then sign back in with the ID you wish to use.  If you don't know the password for your old ID, or if it isn't accepted, go to https//appleid.apple.com, click Manage my Apple ID and sign in with your current iCloud ID.  Tap edit next to the primary email account, tap Edit, change it back to your old email address and save the change.  Then edit the name of the account to change it back to your old email address.  You can now use your current password to turn off Find My iPhone on your device, even though it prompts you for the password for your old account ID. Then go to Settings>iCloud, tap Delete Account and choose Delete from My iDevice when prompted (your iCloud data will still be in iCloud).  Next, go back to https//appleid.apple.com and change your primary email address and iCloud ID name back to the way it was.  Now you can go to Settings>iCloud and sign in with your current iCloud ID and password.

  • How can I save a complete set of bookmarks at once?

    Having searched for ERP/CRM info, I have found several interesting sited offering valuable information. Each of these sites has been opened in a separate screen. By doing so, I collected a series of tabs, each of them connected to a specific website.
    How can I bookmark the whole set of links to my collection of favourites at once, avoiding to save them one by one?

    You're welcome
    If you have a Dutch Firefox version then you need to use the correct shortcut key (Alt+A) to open the Bladwijzers menu.
    *https://support.mozilla.com/nl/kb/Menuoverzicht

  • How can I change the default setting for downloading photos from email?

    How can I change the default setting for downloading photos from emails I receive?  It shows the default as Photoshop Elements 4.0 and is not supported by this system.  That was my last computer!!
    Thanks,
    Sheila

    That has nothing to do with styles nor Pages, it is a System/Printer Driver setting.
    You can experiment to see if the Printer Settings stick with your document, but in the past this has not worked.
    Peter

  • How can i execute that sub menu through Acrobat javascript

    Hi,
    I want to open multiple .pdf files in Acrobat Professional 9 enable the menu item which is
    in Advanced -> Extend Features in Adobe reader.
    "Extend Features in Adobe reader." is a sub menu in "Advance"  menu item.
    How can i execute that sub menu through Acrobat javascript

    Hi,
    The Scripting code is mentioned below:
    var q = app.trustedFunction(
        function ()
             app.beginPriv();
             app.execMenuItem("DIGSIG:UBDoc");
             app.endPriv();
    try{
    q();
    catch(e){
    app.alert("Invalid Menu Item\nPlease Contact the SysAdmin");
    But its not working. Please help me.
    Thanks,
    Christy

  • How can display svg file by using applet

    Hi ,
    my problem is ..
    1. I have one servlet which is generating svg file by using batik package.
    2.There is one Applet which receives SVG file from Servlet ..
    From here i dont have dont doubts.. then my doubt is
    3. How can display that svg file on the browser..
    please help me if u know any ,
    thanks regards,
    Balu

    Maybe this page can help you?
    http://www.w3c.org/Graphics/SVG/

  • I have the iPhone and my own Apple ID. I would like the iPad to have my husbands Apple ID so we are able to communicate with each other (he is deaf). How can FaceTime and iMessage be set up to do this?

    I have the iPhone and my own Apple ID. I would like the iPad to have my husbands Apple ID so we are able to communicate with each other (he is deaf). How can FaceTime and iMessage be set up to do this?

    Log into each device with your own Apple ID's in Settings > iCloud.
    Then, so you can share preiously purchased apps, log into both devices using the Apple ID used to make those purchases, but ONLY in Settings > iTunes and Apps Stores.
    Verify that each device uses your own Apple IDs in Settings > Facetime and Settings > Messages.

  • How can we copy an enhancement set to a different Business Role?

    Experts,
    How can we copy an enhancement set to a different Business Role?
    Currently we have an enhancement to a Business Role "SALES PRO."  How can i make the same enhancement set active for a different Business Role? ie. MARKETINGPRO.
    Thanks,

    Hi,
    it is recommended to have only one active enhancement set per client.
    For your businessrole you could use the role configuration key.
    In our system each businessrole has it´s own role configuration key. But we implemented also a BADI if no configuration is found use our company default role configuration key and only if there is also no configuration use SAP .
    Kind regards
    Manfred

Maybe you are looking for

  • Can no longer print a PDF on Macbook Air - latest OS version

    I had a message recently stating that I the HDD on the Mac was getting close to full, so moved some programs (including Acrobat Professional 11.0.10) and since then, I can't print any files using Acrobat. MS Office files print fine, so don't think it

  • Problem uninstalling virtual PC 7!!!

    I recently installed virtual pc 7 on my powerbook, but after having it run so slow and noticing that i only had 5 gbs left (the windows virtual machine was assigned 20 gigs of my 80) i decided to uninstal it. the uninstall seemed to be successful, ho

  • Can't install iPhoto 11, currently have iPhoto 08

    I am currently using iPhoto '08 version 7.1.5. I have tried to purchase the latest version of iPhoto from app store, but it won't let me. I have tried to uninstall current version but I can't do this either. I have tried to download updates from appl

  • JVM heap parameter setting...

    hi body we have two HP machine. and each machine hardware configration is :  8  CPU  and  40G memory software environment: 1. system sofeware :  HP-UX 11.31  64bit 2. NetWeaver 7.0 (2004s) 3. HP JDK 1.4.2 64bit in machine one, also host one ,  the  M

  • Shift+A not working

    The machine is a Macbook with 2GHz and 1GB ram. Shift+A is not working. The shift key will work when capitalizing any of the other letters except A. Anyone know what this problem is?