Searching a jtree with string

hi guys!
i am searching a JTree with a "string"
now i want to go the specific node (all expanded)
by matching the string to the node
how do i do it
any suggestions
thank u

class FindAction extends KeyAdapter {
    private ModelTree               tree;
    private DefaultMutableTreeNode  found;
    private Enumeration             nodes;
    private Stack                   history;
    public FindAction(ModelTree tree) {
        this.tree = tree;
        found = null;
        history = new Stack();
    public void keyTyped(KeyEvent event) {
        String text = ((JTextField)event.getSource()).getText();
        switch (event.getKeyChar()) {
        case KeyEvent.VK_ENTER:
            if (text.equals("")) nodes = tree.topNode.preorderEnumeration();
            break;
        case KeyEvent.VK_BACK_SPACE:
            try {
                TreePath path = (TreePath)history.pop();
                tree.setSelectionPath(path);
                tree.scrollPathToVisible(path);
            } catch (EmptyStackException ese) {}
            return;
        default:
            text += event.getKeyChar();
            if ((found != null) && found.toString().startsWith(text)) {
                return;
            if (nodes == null) {
                nodes = tree.topNode.preorderEnumeration();
            break;
        if ((found = find(text)) == null) {
            // try it one more time from the top
            nodes = tree.topNode.preorderEnumeration();
            found = find(text);
        try {
            TreePath path = new TreePath(found.getPath());
            tree.setSelectionPath(path);
            tree.scrollPathToVisible(path);
            history.push(path);
        } catch (NullPointerException e) {}
    private DefaultMutableTreeNode find(String searchString) {
        while (nodes.hasMoreElements()) {
            DefaultMutableTreeNode node = (DefaultMutableTreeNode)nodes.nextElement();
            if (node.toString().startsWith(searchString)) {
                return node;
        return null;
}

Similar Messages

  • How can I search the tree with a given string?

    How can I search the tree with a given string?
    I don't find any function like "search(...)".
    I want to find the tree nodes which include the given string.
    Thanks.

    Try it with .com instead of .ca - fixes it for me (corporate firewall blocks .ca here)
    http://spendolini.blogspot.com/2013/09/working-with-apex-tree.html
    Anyway - it links to an article of mine which describes interacting with the tree: Tom's Blog: Working with the tree in Apex. There is also a demo application on apex.oracle.com: http://apex.oracle.com/pls/apex/f?p=54687:38

  • 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());

  • Search for calendars with exact match

    Hello,
    I am work on customisation of uwc. I have problem with calendar search. I am getting the result of substring matches. I want to have exact matches. I suppose that it is some kind of configuration of Sun Calendar Server. Could you give me please some advices?
    Thank you

    Hi,
    jslezak wrote:
    I am work on customisation of uwc. I have problem with calendar search. I am getting the result of substring matches. I want to have exact matches. I suppose that it is some kind of configuration of Sun Calendar Server. Could you give me please some advices?Which screen are you talking about precisely? Is this the calendar subscription search screen or the attendee search screen?
    A number of the searches are controlled by the calendar ics.conf file. So try matching the directory access entry which relates to your search to the appropriate string in ics.conf and that should provide a guide as to what needs to be changed.
    Regards,
    Shane.

  • Regex with strings that contain non-latin chars

    I am having difficulty with a regex when testing for words that contain non-latin characters (specifcally Japanese, I haven't tested other scripts).
    My code:
    keyword = StringUtil.trim(keyword);
    //if(keywords.indexOf(keyword) == -1)
    regex = new RegExp("\\b"+keyword+"\\s*;","i");
    if(!regex.test(keywords))
    {Alert.show('"'+keywords+'" does not contain "'+keyword+'"'); keywords += keyword + "; ";}
    Where keyword is
    日本国
    and keywords is
    Chion-in; 知恩院; Lily Pond; Bridge; 納骨堂; Nōkotsu-dō; Asia; Japan; 日本国; Nihon-koku; Kansai region; 関西地方; Kansai-chihō; Kyoto Prefecture; 京都府; Kyōto-fu; Kyoto; Higashiyama-ku; 東山区; Places;
    When the function is run, it will alert that keywords does not contain keyword, even though it does:
    "Chion-in; 知恩院; Lily Pond; Bridge; 納骨堂; Nōkotsu-dō; Asia; Japan; 日本国; Nihon-koku; Kansai region; 関西地方; Kansai-chihō; Kyoto Prefecture; 京都府; Kyōto-fu; Kyoto; Higashiyama-ku; 東山区; Places; " does not contain "日本国"
    Previously I was using indexOf, which doesn't have this problem, but I can't use that since it doesn't match the whole word.
    Is this a problem with my regex, is there a modifier I need to add to enable unicode support or something?
    Thanks
    Dave

    ogre11 wrote:
    > I need to use refind to deal with strings containing
    accented characters like
    > ?itt? l?su, but it doesn't seem to find them. Also when
    using it with cyrillic
    > characters , it won't find individual characters, but if
    I test for [\w] it'll
    > work.
    works fine for me using unicode data:
    <cfprocessingdirective pageencoding="utf-8">
    <cfscript>
    t="Tá mé in ann gloine a ithe;
    Nà chuireann sé isteach nó amach
    orm";
    s="á";
    writeoutput("search:=#t#<br>for:=#s#<br>found
    at:=#reFind(s,t,1,false)#");
    </cfscript>
    what's the encoding for your data?

  • Batch File Search and Replace a String

    I've written a batch file to handle the copying of files.  I'm trying to reduce the number of parameters that I pass to the batch file.
    I want the batch file to perform a string replace on the directory path that is passed as a parameter to the batch file.
    Here is how I run the batch file:
    COPY_FILE.BAT C:\DATA\FTP_DATA\ACME\IN      (I'm passing directory path "C:\DATA\FTP_DATA\ACME\IN" as parameter %1)
    So my batch file will copy a file to the directory path represented by parameter %1.
    But then I want the file copied to a second directory.  I want the batch file to replace string "FTP_DATA" in the directory path with string "FTP_DATA\ARCHIVE"
    I know I could pass this path as a second parameter, but I want to limit the number of parameters so figured I could have the batch file perform a search and replace on string "FTP_DATA".
    After searching the internet, I thought I found the answer by using the following command in the batch file:
    set ARCHIVE_PATH=%1:FTP_DATA=FTP_DATA\ARCHIVE
    But it doesn't perform a search and replace.  It just appends to the directory path with the following result:
    C:\DATA\FTP_DATA\ACME\IN:FTP_DATA=FTP_DATA\ARCHIVE
    What I want is the this:
    C:\DATA\FTP_DATA\ARCHIVE\ACME\IN
    Any suggestions?

    Your syntax is not correct. Example:
    @echo off
    setlocal enableextensions
    set ARCHIVE_PATH=C:\DATA\FTP_DATA\ACME\IN
    echo %ARCHIVE_PATH%
    set ARCHIVE_PATH=%ARCHIVE_PATH:FTP_DATA=FTP_DATA\ARCHIVE%
    echo %ARCHIVE_PATH%
    endlocal
    -- Bill Stewart [Bill_Stewart]

  • Using JTree with checkbox

    Hi All,
    I have a link for implementation of JTree with Checkbox
    http://www.jroller.com/santhosh/date/20050610 He has implemented exactly what i want but i am unable to understand the use of all the classes. Really difficult to understand
    So what i did was create a few objects with Checkbox class from AWT package and then added then to JTree using the DefaultMutableTreeStruture i got the tree working but not able to get the Checkboxex
    Can any one explain me how i can implement this senario
    I am trying different search creterias but unable to find a right detailed explanation to my query
    Rgds
    Aditya

    where did you find DefaultMutableTreeStructure?

  • How do I search for lines with a particular pattern and delete them when a match occurs

    How do I search for lines with a particular patter and delete them when a match occurs? For example delete lines containing SUB_NAME = "?" where ? is any string. 

    How do I search for lines with a particular patter and delete them when a match occurs? For example delete lines containing SUB_NAME = "?" where ? is any string. 
    Lines in what? And what language are you using to develop with?
    Are the lines in a text file? A RichTextBox? A TextBox? Some other control? A List(Of String)?
    Is there some expectation by you that by providing what you wrote in your question post that the knowledge in your mind about what you are thinking about will mysteriously emanate to anybody reading your post so all of the sudden your knowledge will
    become their knowledge and they will be able to provide you with an answer as they will suddenly understand what you are trying to do? Because that's probably impossible. Most people try providing enough information in a question so anybody, even stupid people
    like me, can understand what they want. Maybe you should try that. As well as selecting an appropriate forum for your question in the future. Usually a question like this is related to programming in a particular language therefore a language forum may be
    a good choice. Or not.
    La vida loca

  • How i do search in list with textinput

    how i do search in list with textinput ?
    i make textinput with list and list have data i want to do search in list when right my information in textinput

    On change event of TextInput, apply a filter.I am giving sample code over here:
    private function filter():void {
                                            (your list dataprovider).filterFunction = filterMyArrayCollection;
                                             (your list dataprovider).refresh();
                                  private function filterMyArrayCollection(item:Object):Boolean {
                                            var searchString:String = (Your textinput id).text.toLowerCase();
                                            var itemName:String = (item.(property of list provider which is to be searched) as String).toLowerCase();
                                            return itemName.indexOf(searchString) > -1;
    This will help you in following manner:
    when you type "D" in textinput, the list will show you the names which start with "D" or include the letter "D" in their spelling.

  • Sorry, something went wrong - Open Office File from Search Results Page with Office Web Apps

    Hi,
    I'm getting "Sorry, something went wrong" error when I'm trying to open any office document from inside Search Results Page with Office Web Apps, the same error is appearing in the document preview as well.
    The error in SharePoint logs says that the file cannot be found.
    Please note that this error is coming only when the "Filename" of the document is not written in English (in my case its written with Arabic characters).
    If I try to open it from the document library, its opening properly with no errors.
    The only difference between two URLs (document URL in Search Results and in Document Library) is the value for "sourcedoc" attribute;
    In the case of Search Results page, the filename in "sourcedoc" attribute is kept as is with Arabic characters.
    While in the Document Library, the filename in "sourcedoc" attribute is converted into different characters (something like: "B9%D9%85%D9%8").
    Anybody have an idea on how to overcome this issue, implement a workaround or modify the "sourcedoc" behavior?
    Thanks in Advance.
    Hamza AlSughier

    Dear Wendy,
    Thanks for your efforts, I already tried your last suggestion before, but this didn't solve my problem.
    Actually my end users are accessing this portal using ADFS and HTTPS.
    Finally I got this solved, I have done below to get my overall solution working perfectly:
    - First I have configured Windows Authentication and ADFS Authentication on the same zone which is the default zone.
    - The issue when opening office documents with Arabic file name has disappeared as a result of first change.
    - Then I have faced an issue where we are not able to crawl content under Default zone, however we have to do so, after too many efforts, I found that its related to the Load-balancer/proxy, I have made the crawler server
    to crawl himself (http://CrawlServerName:PortNumber).
    - Also a change on Alternate Access Mapping was needed, I have set one of the extended zones (which is running Windows Authentication only) as Internal URL for the Default Zone, and this is was the URL I used for Crawling.
    I have configured Server Name Mappings to make sure we got proper URLs in Search Results.
    - Then we faced another issue, which is Authentication selection on login page (How to bypass this page, and authenticate using ADFS auto), I used this solution (Set Custom Sign In Page):
    http://0ut0ftheb0x.wordpress.com/2014/01/04/skip-the-authentication-selection-page-at-_logindefault-aspx-in-a-mixed-authentication-environment/.
    - I faced one more issue as a result of above workaround; Sign Out functionality wasn't working well; users get logged in automatically whenever I click on Sign Out. I solved this by modifying the "Sign Out" Control under _layouts;
    I made it to redirect users to ADFS Sign Out Page instead of SharePoint Sign Out Page (I know its not recommended, but I don't have any other option).
    Hamza AlSughier

  • Read Document in FileUtilities  cannot search a file with french character in the file name

    Hi,
    I am trying to search a file with french character in the file name like 'captures écran.doc' in my unix server directory, and Write the file somewhere, say in a list of documents or, write on file system to another directory.
    I am using to Read Document in FileUtilities of Foundation, but it cannot read the file due to french character in its name. Although it can find any other file name without these french characters.
    Tried renaming but that also cannot find the file with french character name.
    Please provide any idea to solve it using LC operation.
    Regards,
    Rohan Raj.

    Hi Thomas,
    Thanks for the post, but I have already found a solution to it a month ago. Sorry for not posting the solution.
    You just have to set the '-Djava.property.file.encoding=ISO8859-1' into JVM argument of your server startup, and bounce the server back to pick the new JVM arg set. And now the service Read Document in FileUtilities of Foundation will read all french characters.
    ISO8859-1refers to "Latin alphabet no. 1," consisting of 191 characters from the Latin script. This character-encoding scheme is used throughout The Americas,Western Europe, Oceania, and much of Africa. It is also commonly used in most standard romanizations of East-Asian languages.
    regards,
    Rohan Raj.

  • How to search for a pattern string in entire registry and delete all the keys and subkeys that contain the pattern (C# or VB)?

    I want to search for a pattern string in the entire registry and need to delete all the keys and sub-keys that contain the pattern. How can I implement this in VB Script or C#? Appreciate if you can give some sample examples. Now every time, I am manually
    searching for the pattern in registry and deleting one by one.
    Thanks Prasad

    There is no built in way to do this. You'll end up having to enumerate all keys and values in the entire registry and comparing each one for a pattern using Regex or similar.  This is going to be really slow but there isn't much else you can do about
    it (other than parallelize the enumeration).  Also note that you won't have permissions to all keys for read and/or write access so you'll need to skip over those using exception handling.
    Michael Taylor
    http://blogs.msmvps.com/p3net

  • Urgent!!!!!! Issue with String in CO

    Hi All,
    I am learner of OAF.
    I have issue with string while converting into double.
    In AM,
    public String ComputeMarginPercent()
    retrun form.format((55570.0*100)/184.64999999999418);
    in CO..I am getting the value:
    String s1 = (String)oapagecontext.getApplicationModule(oawebbean).invokeMethod("computeMarginPercent");
    here getting value of s1=30,094.77
    I need to convert s1 to double, while converting double its raising error.
    how can I remove comman in (30,094.77) this number..?
    please advise me ..

    Hi Pratap,
    I am new to java ..
    Can you please tell me in step by step..?
    Thanks in advance
    I tried like /..
    String str= "30,094.77 ";
    char[] chars = str.toCharArray();
    String s = String.copyValueOf(chars);
    System.out.println(s);
    Still displaying value as 30,094.77 (with comma)
    Edited by: user633508 on Nov 21, 2008 2:55 AM

  • Problem with String variable

    I am new to Java Programming.
    I have a line of code that works and does what is supposed to.
    faceData.getProfile("Lisa").removeFriend("Curtis");
    If I assign the strings to variables such as-
    String name = "Lisa";
    String fName = "Curtis";
    and then plug those into the same line of code, it does not work
    faceData.getProfile(name).removeFriend(fName);
    What could be causing the problem?
    I even added some lines to print out what is stored in the variables to verify that they are what they should be, but for some reason the variables do not work while putting the strings in quotes does. Any ideas?

    I guarantee that something about your assertions are incorrect. Those variables are either not equal to the values you claim, or something else is going on. But it's not a problem with string variables versus string constants.
    Edit: My best guess in lack of a real example from you, is that the strings in question have non-printable characters in them, such as trailing spaces or line feeds.

  • Displaying a jtree with checkboxes and enabling some default checkboxes

    I have created a jtree displaying a list of nodes hierarchically ,and created a checkbox for each node as well.
    My problem is having created the jtree with checkboxes i need to have some of the nodes in the hierarchy checked by default on first launch of the gui.To do this i read a list of treepaths from a file and would want to traverse the tree and enable the node after finding it,which is what i am having issue with.
    Your solution would be appreciated as i am a newbie and having got this far, feel like i need some back up :)
    Thanks & Regards
    Shashi

    I have created a jtree displaying a list of nodes hierarchically ,and created a checkbox for each node as well.
    My problem is having created the jtree with checkboxes i need to have some of the nodes in the hierarchy checked by default on first launch of the gui.To do this i read a list of treepaths from a file and would want to traverse the tree and enable the node after finding it,which is what i am having issue with.
    Your solution would be appreciated as i am a newbie and having got this far, feel like i need some back up :)
    Thanks & Regards
    Shashi

Maybe you are looking for

  • Transfer itunes library from windows pc to new macbook pro?

    I have a new Macbook Pro on the way. This is my first Mac ever.I just want to know how I can transfer my itunes library from my windows pc to my new Macbook Pro?Thanks for the help.I am sure I am going to have alot more questions on Tuesday when I ge

  • AJAB - FY Closing

    Hi, When we execute AJAB to close a FY for FI-AA, does the system prevent any other user from performing a asset transaction in that FY, or from changing asset master record such as depre start date? Or will such an action cause the FY closing to abo

  • Setup AOL e mail to firefox

    I canceled my AOL however I am keeping the E Mail ....when using Firefox I am on pages that I wish to send e mail the AOL does not appear how do I set up the AOL e mail so that when on someones home page with Firefox wish to send a e mail from someon

  • Attach Srf File to project

    Hi, Sorry for this post, the response is probably already in the forum but the search function is down. I've made a form with screen painter; so I got a .srf file. I know I have to use the method "LoadBatchActions" to load it. How can I join it in th

  • AT&T Modem Router + Apple Airport Extreme = ?

    Nobody from AT&T can seem to answer this so I turn to you knowledgeable folks!In short, my Uverse internet and cable service is set to be installed on Saturday 6/22. The question that nobody from AT&T can't seem to answer is how I would set up my net