How to get total number of nodes in a JTree?

Hi,
I am trying to get total number of nodes in a JTree, and cannot find a way to do it.
The current getRowCount() method returns the number of rows that are currently being displayed.
Is there a way to do this or I am missing something?
thanks,

How many nodes does this tree have?
import java.awt.EventQueue;
import javax.swing.*;
import javax.swing.event.TreeModelListener;
import javax.swing.tree.*;
public class BigTree {
    public static void main(String[] args) {
        EventQueue.invokeLater(new Runnable() {
            public void run() {
                TreeModel model = new TreeModel() {
                    private String node = "Node!";
                    @Override
                    public void valueForPathChanged(TreePath path,
                            Object newValue) {
                        // not mutable
                    @Override
                    public void removeTreeModelListener(TreeModelListener l) {
                        // not mutable
                    @Override
                    public boolean isLeaf(Object node) {
                        return false;
                    @Override
                    public Object getRoot() {
                        return node;
                    @Override
                    public int getIndexOfChild(Object parent, Object child) {
                        return child == node ? 0 : -1;
                    @Override
                    public int getChildCount(Object parent) {
                        return 1;
                    @Override
                    public Object getChild(Object parent, int index) {
                        return node;
                    @Override
                    public void addTreeModelListener(TreeModelListener l) {
                        // not mutable
                JFrame frame = new JFrame("Test");
                frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
                frame.getContentPane().add(new JScrollPane(new JTree(model)));
                frame.pack();
                frame.setLocationRelativeTo(null);
                frame.setVisible(true);
}But for bounded tree model using DefaultMutableTreeNode look at bread/depth/preorder enumeration methods to walk the entire tree. Or look at the source code for those and adapt them to work with the TreeModel interface.

Similar Messages

  • How to get total number of days

    Hi All,
    how to get total number of days , for example if month eq 05 then need to get total number of days until MAY 31.
    and how to get total number of days in a month.
    Thank You,,
    Sriii..

    Hi Sridhar,
    Pls Try to search before posting general questions.
    Try this,
    CALL FUNCTION 'DAYS_BETWEEN_TWO_DATES'
        EXPORTING
          i_datum_bis                   = p_lv_date1
          i_datum_von                   = p_lv_date2
       IMPORTING
         e_tage                        = p_e_date_difference
       EXCEPTIONS
         days_method_not_defined       = 1
         OTHERS                        = 2
      IF sy-subrc  0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
             WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
      ENDIF.
    Regards,
    Sunil kairam.

  • How to get total number of result count for particular key on cluster

    Hi-
    My application requirement is client side require only limited number of data for 'Search Key' form total records found in cluster. Also i need 'total number of result count' for that key present on the custer.
    To get subset of record i'm using IndexAwarefilter and returning only limited set each individual node. though i get total number of records present on the individual node, it is not possible to return this count to client form IndexAwarefilter (filter return only Binary set).
    Is there anyway i can get this number (total result size) on client side without returning whole chunk of data?
    Thanks in advance.
    Prashant

    user11100190 wrote:
    Hi,
    Thanks for suggesting a soultion, it works well.
    But apart from the count (cardinality), the client also expects the actual results. In this case, it seems that the filter will be executed twice (once for counting, then once again for generating actual resultset)
    Actually, we need to perform the paging. In order to achieve paging in efficient manner we need that filter returns only the PAGESIZE records and it also returns the total 'count' that meets the criteria.
    If you want to do paging, you can use the LimitFilter class.
    If you want to have paging AND total number of results, then at the moment you have to use two passes if you want to use out-of-the-box features because LimitFilter does not return the total number of results (which by the way may change between two page retrieval).
    What we currently do is, the filter puts the total count in a static variable and but returns only the first N records. The aggregator then clubs these info into a single list and returns to the client. (The List returned by aggregator contains a special entry representing the count).
    This is not really a good idea because if you have more than one user doing this operation then you will have problems storing more than one values in a single static variable and you used a cache service with a thread-pool (thread-count set to larger than one).
    We assume that the aggregator will execute immediately after the filter on the same node, this way aggregator will always read the count set by the filter.
    You can't assume this if you have multiple client threads doing the same kind of filtering operation and you have a thread-pool configured for the cache service.
    Please tell us if our approach will always work, and whether it will be efficient as compared to using Count class which requires executing filter twice.
    No it won't if you used a thread-pool. Also, it might happen that Coherence will execute the filtering and the aggregation from the same client thread multiple times on the same node if some partitions were newly moved to the node which already executed the filtering+aggregation once. I don't know anything which would even prevent this being executed on a separate thread concurrently.
    The following solution may be working, but I can't fully recommend it as it may leak memory depending on how exactly the filtering and aggregation is implemented (if it is possible that a filtering pass is done but the corresponding aggregation is not executed on the node because of some partitions moved away).
    At sending the cache.aggregate(Filter, EntryAggregator) call you should specify a unique key for each such filtering operation to both the filter and the aggregator.
    On the storage node you should have a static HashMap.
    The filter should do the following two steps while being synchronized on the HashMap.
    1. Ensure that a ConcurrentLinkedQueue object exists in a HashMap keyed by that unique key, and
    2. Enqueue the total number count you want to pass to the aggregator into that queue.
    The parallel aggregator should do the following two steps while being synchronized on the HashMap.
    1. Dequeue a single element from the queue, and return it as a partial total count.
    2. If the queue is now empty, then remove it from the HashMap.
    The parallel aggregator should return the popped number as a partial total count as part of the partial result.
    The client side of the parallel aware aggregator should sum the total counts in the partial result.
    Since the enqueueing and dequeueing may be interleaved from multiple threads, it may be possible that the partial total count returned in a result does not correspond to the data in the partial result, so you should not base anything on that assumption.
    Once again, that approach may leak memory based on how Coherence is internally implemented, so I can't recommend this approach but it may work.
    Another thought is that since returning entire cached values from an aggregation is more expensive than filtering (you have to deserialize and reserialize objects), you may still be better off by running a separate count and filter pass from the client, since for that you may not need to deserialize entries at all, so the cost on the server may be lower.
    Best regards,
    Robert

  • How to get total number of days in current Fiscal period/year

    Hi,
    I need to get total number of days in current Fiscal period/year (current month) and assign it to an infoobject. I need a routine for this. Is there any function module to get this.If possible pls paste the ABAP code also for this task. Thanks in advance

    here is the FM:
    LAST_DAY_IN_PERIOD_GET
    KJ!!!

  • How to get Total Number of XML Nodes?

    Hello All,
    I have a Flash program I'm doing in Actionscript 3, using CS6.
    I'm using the XMLSocket Class to read-in XML Data. I will write some sample XML Data that is being sent to the Flash
    program below...
    I know with this line here (below) I can access the 4th "element or node" of that XML Data.
         Accessing XML Nodes/Elements:
    // *I created an XML Variable called xml, and "e.data" contains ALL the XML Data
    var xml:XML = XML(e.data);
    // Accessing the 4th element of the data:
    xml.MESSAGE[3].@VAR;          --->     "loggedOutUsers"
    xml.MESSAGE[3].@TEXT;         --->     "15"
         SAMPLE XML DATA:
         <FRAME>
    0               <MESSAGE VAR="screen2Display" TEXT="FRAME_1"/>
    1               <MESSAGE VAR="numUsers" TEXT="27"/>
    2               <MESSAGE VAR="loggedInUsers" TEXT="12"/>
    3               <MESSAGE VAR="loggedOutUsers" TEXT="15"/>
    4               <MESSAGE VAR="admins" TEXT="2"/>
         </FRAME>
    I'm new to Flash and Actionscript but I'm very familiar with other languages and how arrays work and such, and I know for
    example, in a Shell Script to get the total number of elements in an array called "myArray" I would write something like
    this --> ${#myArray[@]}. And since processing the XML Data looks an awful lot like an array I figured there was maybe
    some way of accessing the total number of "elements/nodes" in the XML Data...?
    Any thoughts would be much appreciated!
    Thanks in Advance,
    Matt

    Hey vamsibatu, thanks again for the quick reply!
    Ohhh, ok I gotcha. That makes more sense.
    So I just tried this loop below and I guess I could use this and just keep assigning an int variable to the output so
    when it finishes I will be left with a variable containing the total number of elements:
    for (var x:int in xml.MESSAGE)
         trace("x == " + x);
    *Which OUTPUTS the Following:
    x == 0
    x == 1
    x == 2
    x == 3
    x == 4
    So I guess I could do something like this and when the loop completes I will be left with the total number of elements/nodes...
    var myTotal:int;
    for (var x:int in xml.MESSAGE)
        myTotal = x;
    // add '1' to myTotal since the XML Data is zero-based:
    myTotal += 1;
    trace("myTotal == " + myTotal);
    *Which Prints:
    "myTotal == 5"
    Thanks again for you suggestions, much appreciated!
    I think that should be good enough for what I needed. Thanks...
    Thanks Again,
    Matt

  • How to get total number of pages from .doc file without using Office interop?

    Hi,
    Kindly help me in getting the total number of pages from a .doc file not .docx file using C#. I know how to get by using Office interop but I do not want to use Office interop.
    So, without office automation in C# let me know how to get the total number of pages from a .doc file.
    Regards,
    Ashok

    Hi Ashok,
    >> I know how to get by using Office interop but I do not want to use Office interop
    Could you tell us why you don't want to use Office interop?
    As far as I know, this is the easiest way to achieve.Hmmm,this is my answer
    http://msdn.microsoft.com/en-us/library/microsoft.office.interop.word.pagenumbers.startingnumber(v=office.14).aspx
    Best regards,
    Kristin
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • How to get total number of licenses

    Hi everyone,
    Who knows how to get the total number of licenses, I am using SBO 2005 PL07+VB.Net. from SDK help file I saw there is a SAP Business One License API, but I cann't find this API from object browse, who knows which file contents the license API.
    Thanks in advance!
    Kathy

    Hi Kathy,
    Since (un-?)fortunately the license server has been moved from DCOM to CORBA, this information is currently obsolete (I still hope we will get this information through the SDK some time in future...).
    As an interim solution you will have to get this information from the B1LicenseFile.txt file through some small application you write (you could have e.g. a service that writes the information you are interested in into some table in some database - and retrieve this information through a SQL statement).
    HTH,
    Frank

  • FTP: how to get total number of files in directory

    Hello Folks,
    I prefer to use FTP from the command line but cannot figure out how--after having connected to a remote directory via ftp--to list the total number of files in that directory.
    In Unix, I would do this:
    % ls | wc -l
    But hopefully there is also some way in FTP to do the same--but darned if I know how! I do see that FTP clients such as Transmit have this listing, but maybe that's a feature of the software and not ftp.
    Thanks in advance for any suggestions/tips.
    Doug

    I've done a lot of ftp scripts 10 years ago, mostly because I could not guarantee my scripted telnet would be available everywhere. The best answer today though is listed throughout this thread and that is to use the ssh family of commands that include ssh for secure remote shell, scp for secure remote copy and sftp which is the ftp interface to scp.
    My point is neither telnet or ftp are considered safe or secure anymore because listening to communications is popular, it is referenced in most "wizard" magazines, and usernames and passwords are not encrypted.
    Set up your environment first with ssh-keygen. Version 2 is more secure than version 1 if both are still offered. Then use "ssh user@hostname ls | wc -l" to get your number of files. It is simple execution with one command and returns a status.
    If you are really looking for a solution using what you are familar with and want to ignore advice concerning security, here is a sample batch script (untested). You can change the filenames, usernames, and hostnames as desired.
    rm dir.out 2> /dev/null
    echo "user sampleuser samplepw" > script.ftp
    echo "dir sampledirectory dir.out" >> script.ftp
    echo "quit" >> script.ftp
    ftp -n sample.hostname < script.ftp
    if [ ! -r dir.out ] # file not created
    then
    echo login failed
    elif [ ! -s dir.out ] # file created but empty
    then
    echo directory is empty
    else
    nf=`wc -l dir.out | cut -f1`
    echo "There are $nf files in the directory"
    fi

  • How to get total number of products for the site?

    Hi,
    I want to know the total number of products available for the site. i checked in the dcs_product table, it shows 40849 unique products. is this the total number of products count which are used in the site?
    I have another table in CATA schema dcs_product_sites, when i run the CatalogMaintenanceService to populate the records in this table, getting only 26000 products. Please let me know why this difference when i run the service.
    Thanks

    dcs_product table gives all products in your catalog.
    dcs_product_site will give products for a particular site.
    If you have more than one site, then you need to query for that particular site.
    And the number of products you show also depends upon the start and end date on the products.
    And also some custom filters you have like Out of stock items etc.
    Peace
    Shaik

  • How to get total number of plants, employees, jobs and respective tasks

    Hi Gurus,
    I have requirement where in I need to give client information about root object. Information being sought is on the total number of plants, employees, jobs and respective tasks performed by employees.
    Is there any standard report available to fetch this information? Or please let me know how to collect all this information?
    Thanks in Advance.
    Rupali

    Total number of employees S_AHR_61016369
    Jobs S_AHR_61016497
    Tasks S_AHR_61016522, S_AHR_61016523 & S_AHR_61016524

  • How to get total number of Database connections from Java code

    Hi,
    I am using Myql4.1.12.
    I am conncting to mysql through Java.
    I want to know how many active database connections were running at a specific time. Is it possible?
    Can you please help me.
    Thanks in advance.

    Seems like this would be a question for MySql, not for Java. And if it's possible you'd run some MySql utility to do that, not code it in a Java app.

  • How to get total number of rows return by query

    hi all
    i am using forms 6i with oracle 10G in windows environment....
    i have a tabular form now i want to know that how many rows return by the query...like when user click on enter query and then give any search criteria and then execute query..it displays the records but i want to count the records that how many rows are return.............
    hope you understant what i mean
    Thanks in advance
    Regards

    U can use
    "Select count(*) from <table> where <condition>"
    <condition> is the where clause being used during "Execute Query"
    this will give u the no of records in query.
    And second option is to take a summary column. whose function is set "COUNT" and
    "Summarized item" should contain a column that will never be blank. After execute query this column will give u no of records in block.
    Regards....

  • How to get total number of times excuted the report

    hi,
    Can you spend for a while.
    Requirement is when the Monthly summary report: When report executed then in the header it has to display how many times times this is executed and data has to display(this completed).
    For example out put is:
    No.of times executed:20   (means this is 20th time this report is running)
    here data has to display(This i completed).
    Thank you,
    Anu.

    Anitha Reddy wrote :
    Requirement is when the Monthly summary report: When report executed then in the header it has to display how many times times this is executed and data has to display(this completed).
    For example out put is:
    No.of times executed:20 (means this is 20th time this report is running)
    here data has to display(This i completed).
    If you completed everything then what is your problem ??

  • How count the total number of instances ?

    I have 2 scenarios :-
    1. How to get the total number of instances of  the node  in a BO?
    eg :
    businessobject BO1   {
    element BO_ID;
                       node NODE1 [0..n]
                         element Node_ID;
                         element Status ;
                         element value:
    I want to get total number of the NODES instances in the particular instance of the BO1.   !!!?????
    2. I want to  make some calculations based on the attributes of the NODE1 , in the   BeforeSave .absl  of the Business Object BO1.
    eg:
    something like this :-
    In BeforeSave of BO1.absl -
    for ( all the instances in NODE1 )
    {   if (NODE1.status == true)
                 sum = sum + NODE1.value
    Please help !!!!

    Your approach is correct.
    You can use a standard Query or create your own Query to run through Datainstances.
    Documentation with examples for Queries in ABSL see here: https://my020062.sapbydesign.com/sap/ap/ui/repository/SAP_BYD_WEKTRA/CP/sapLSUIContentPlayerTestPage.html?manifest=067D03A7602B1D490899DF46B5082089&COMPONENT=A1S_PDI&RELEASE=260&LANGUAGE=en&REGION=&INDUSTRY=&TASK=CR_VIEW&sap-language=EN
    Looking / Clincking  for "SAP Business ByDesign Scripting Language" and "Syntax for Implementation of Actions and Events" and "Query"

  • How to retrieve total number of pages in a report of Instance - RAS SDK ?

    Hello All,
    Hope all is well. I am using BOXI R2 Enterprise and was wondering how to get total # of pages of an Crystal Report Instance using RAS SDK.
    Thanks in advance,
    Sam

    How do i retrieve the total number of pages in a report-- via RAS SDK
    Sincerely,
    Ted Ueda

Maybe you are looking for

  • Error Code About Chinese Output

    I developed a report using XML PUBLISHER, but the output chinese is error code! pls tell me the reason,thanks!

  • How can I update my iPod on a new laptop?

    So, iOS 5 is finally out next week. I would like to upgrade to it, however since my old laptop is broke I use my mums laptop for iTunes. How can I update my system without apps beinf rid of? Last time I did it, my apps remaines intact, but I don't kn

  • After Upgrade R12.1.3 Invalid OBjects Found

    Hi Friends, My Environment* Application Version: 12.1.3 Db Version : 11.1.0.7 OS Version : OEL4U5 Recently I have upgraded My application from R12.1.1 to R12.1.3 and upgraded successfully, After upgrade i found that lot of invalid Objects are in Appl

  • Is there an app for BC sage line 50 integration

    Is there an app for BC sage line 50 integration so visitors can draw down invoices and elivery notes onto theire web area

  • X only works as root

    I have started X fine as root, but it doesn't start as a normal user. FATAL: Module fbcon not found. (EE) VESA(1): Cannot read V_BIOS (3) Input/output error