JTree in JScrollpane, find out

I have following constellation:
A JTree in a JScrollpane with a vertical scrollbar.
Most nodes are hidden "behind the scrollpane" and only view are seen.
I search for a property which signals if a node is currently seen on screen and which are "scrolled" (that means those nodes which aren't visible) (the jcomponent method isVisible() doesn't work)
I think about such a method which uses the information of the scrollbarposition and the dimension of the jviewport but i can't get the information which node is seen if some nodes are expanded and some are collapsed.
Does anybody know such a property or method?
Or is there a SWING-THING which solves the problem?
Thank you for your answers

isVisible() is a "Component-Method" which means i have to take the rendered component finding out the visible nodes.
my application is following:
i write a method which expand all nodes until the leafs are visible but because of performance (i have more than 1000 nodes directly under the root) i want to expand only the nodes which are showing and expand the other later.

Similar Messages

  • JTree: how to find out if its up to date

    I have a JTree and my nodes can be changed from outside of my application.
    It behaves rather weired if new nodes appeare or disapeare. I have a function to update it but how should my programm know when to do so? Is any event fired if i click on a node (resp its ghost) that is not there any more or on one that has more, less or different childs then it displays?
    Or is an update button the best i can have?

    The problem is that the tree represents a structure in a database and it would be a strange thing to do to have the database inform every client.
    I want to do as few mirroring so i intend to make treenodes that access the databse directly. now if the databse is changed from elswhere and i select a node i want it to update. For added nodes this is possible if you click at the parent but ghosts of removed nodes don't fire treeselction events as far as i found out.

  • How to find out the containing jinternalframe?

    anyone know the solution to this problem?:
    1. i have a jinternalframe
    2. in the jinternalframe i have a jlist
    3. each list cell is rendered with a jlabel
    4. i have an action emanating from one of the list cells
    5. in the action handler, i need to get a reference to the containing internalframe
    of the component that is the source of the event (the jlabel rendered inside
    the jlist).
    in java 5, oddly, SwingUtilities.getAncestorOfClass() (that is, walking up the
    component hierarchy) works.
    in java 6, it doesn't.
    the problem is that jlists and other such model components are leaf components.
    they represent a discontinuity in the component containment hierarchy. the poor
    list cell renderers are and must remain dumb.
    anyhow, back to my question: is there any way to find out the containing
    jinternal frame?
    thanks, eitan

    is there any way to find out the containing jinternal frame?Not sure about the Renderer part, but here's a simple demo that puts a JList in a JScrollPane, which is then put on a JPanel, which is then put on the contentPane of a JFrame. Once the frame has been realized (this is key), there's a recursive method that will find whatever you're looking for.import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class MyFrame extends JFrame
      Component mysteryParent;
      public MyFrame()
        super("Find Parent");
        setName("The Amazing Frame");
        setDefaultCloseOperation(EXIT_ON_CLOSE);
        JList list = new JList();
        JScrollPane scroll = new JScrollPane(list);
        scroll.setName("The Silly Scroll");
        JPanel panel = new JPanel(new BorderLayout());
        panel.setName("The Plain Panel");
        panel.add(scroll, BorderLayout.CENTER);
        Container c = getContentPane();
        c.setLayout(new BorderLayout());
        c.add(panel, BorderLayout.CENTER);
        pack();
        // first, let's try to find the containing frame
        mysteryParent = getParentOf(list, JFrame.class);
        if (mysteryParent != null)
          System.out.println("The frame that contains the list is: " + mysteryParent.getName());
        // then, let's try to find the containing panel
        mysteryParent = getParentOf(list, JPanel.class);
        if (mysteryParent != null)
          System.out.println("The panel that contains the list is: " + mysteryParent.getName());
        // finally, let's try to find the containing scroll pane
        mysteryParent = getParentOf(list, JScrollPane.class);
        if (mysteryParent != null)
          System.out.println("The scrollPane that contains the list is: " + mysteryParent.getName());
      // recursive method:
      public Component getParentOf(Component child, Class parentClass)
        Component parent = null;
        if (child != null)
          parent = child.getParent();
        if (parent == null)
          return null;
        else if (parentClass.isInstance(parent))
          return parent;
        return getParentOf(parent, parentClass);
      public static void main( String[] args )
        MyFrame frame = new MyFrame();
        frame.setVisible(true);
    }I just swagged this just now, so maybe it could be improved.
    I'm guessing that SwingUtilities.getAncestorOfClass() already does this, but I've never used it so I'm not sure.

  • How to find out if JTable's selected row is visible?

    Hello there,
    Given:
    a JTable is inserted into a JScrollPane and the number of rows in the table is greater than the vieport size.
    A random row within the table gets programmatically selected.
    How to find out if the selected row is visible in a JTable visible area?
    Your help will be greatly appreciated.
    Tim

    That will make the row visible, but not answer whether it was visible
    in the first place. Try something like:
    public boolean isRowVisible( JTable table, int row ) {
        Rectangle rect = table.getBounds();
        int rowHeight = table.getRowHeight();
        int viewHeight = table.getParent().getHeight();
        int max = rect.y - viewHeight + 1;
        int rowPos = - rowHeight * row;
        return ( rect.y >= rowPos && rowPos > max );
    }assuming all rows have the same height.
    : jay

  • JTree and JScrollPane problems

    Hello all.
    bear with me a second, so I can explain what is happenning with my code. I have got a java application that is accessing an SQL database (either Oracle or postgreSQL) and inputing the data into a tree.
    More specifically it takes the "enrollment" data and draws into the scrollpane the courses and students enrolled. Everything seems to be working perfectly with the building of the tree.
    but I have a drop down list that can select which years to display (1-4th year). I want the tree in the scrollPane to update when u change the year in the drop down list.
    I have added an ActionListener to the drop down list and it picks up the right selection, and I create a new tree object with the new year details and nothing is changed in the scrollpane.
    This is what the GUI looks like:
    This is my tree class which creates teh tree and adds it to the scrollPane object:
    package Interface;
    import java.awt.*;
    import javax.swing.*;
    import javax.swing.tree.*;
    import java.sql.*;
    import Database.Database;
    public class Tree{
         JTree tree;
         JScrollPane scrollPane;
         public Tree(GridBagConstraints c, Container contentPane, GridBagLayout gridBag, int year){
              //Set up the default table.
              TreeNode root = buildTree("Enrollments", year);
              tree = new JTree(root);
              //Set up a scrollPane for the tree.
              scrollPane = new JScrollPane(tree);
              //Set constraints for the ScrollPane
              c.fill = GridBagConstraints.BOTH;
              c.weightx = 1;
              c.weighty = 1;
              c.gridwidth = 2;
              c.gridx = 0;
              c.gridy = 1;
              c.anchor = GridBagConstraints.CENTER;
              gridBag.setConstraints(scrollPane, c);
              contentPane.add(scrollPane);     
              //Set defaults for teh Tree object.
              tree.expandRow(0);
              tree.setRootVisible(false);
              tree.setEditable(true);     
         public DefaultMutableTreeNode buildTree(String s, int year){
              //Set root of tree.
              DefaultMutableTreeNode node = new DefaultMutableTreeNode(s);
              //Create a database object.
              Database db = new Database();
              //change this bit to get the name's of the courses and add into array.
              ResultSet className = db.query("SELECT name FROM courses WHERE year = "+year);
              DefaultMutableTreeNode course = null;
              DefaultMutableTreeNode name = null;
              try {
                        while(className.next()){
                             String classStr = className.getString("name");
                             course = new DefaultMutableTreeNode(classStr);
                             node.add(course);
                             ResultSet firstName = db.query("SELECT students.name FROM students, enrollments, courses WHERE students.id = enrollments.studentID AND enrollments.courseid = courses.id AND courses.name = '"+classStr+"'");
                             while(firstName.next()){
                                  String nameStr = firstName.getString("name");
                                  name = new DefaultMutableTreeNode(nameStr);
                                  course.add(name);
                   catch(Exception e){
                        System.err.println("" + e.getMessage());
                        e.printStackTrace(System.err);
              return node;
    }This is the GUI class that calls on the tree class and draws the GUI. and the actionlistener for the drop down list.
    package Interface;
         import java.awt.*;
         import javax.swing.*;
         import java.awt.event.*;
    import java.sql.*;
         public class GUI extends JFrame implements ActionListener{
              private static final long serialVersionUID = 1L;     
              DropDownMenu yearDrop;
              ScrollPane scrollPane;
              JMenuItem menuItemSave;
              JMenuItem menuItemQuit;
              JMenuBar menuBar;
              JMenu menu;
              JButton save;
              JButton quit;
              Tree tree;
              String year[] = { "First Year", "Second Year", "Third Year", "Fourth Year" };
              Container contentPane = getContentPane();
              GridBagLayout gridBag = new GridBagLayout();
              GridBagConstraints c = new GridBagConstraints();
              public GUI(){
                   setSize(500,500);
                   setTitle("UTAS Enrollments");
                   contentPane.setLayout(gridBag);          
                   save = new JButton("Save");
                   quit = new JButton("Quit");
                   menuItemSave = new JMenuItem("Save");
                   menuItemQuit = new JMenuItem("Quit");
                   menuItemSave.setMnemonic('s');
                   menuItemQuit.setMnemonic('q');
                   yearDrop = new DropDownMenu(year, c, contentPane, gridBag);
                   tree = new Tree(c, contentPane, gridBag, 1);
                   menuBar = new JMenuBar();
                   menu = new JMenu("File");
                   menu.setMnemonic('f');
                   menuBar.add(menu);
                   menu.add(menuItemSave);
                   menu.add(menuItemQuit);
                   setJMenuBar(menuBar);
                   //Set constraints for the Save button
                   c.fill = GridBagConstraints.NONE;
                   c.weightx = 1;
                   c.weighty = 0;
                   c.gridwidth = 1;
                   c.gridx = 0;
                   c.gridy = 2;
                   c.anchor = GridBagConstraints.WEST;
                   save.setMnemonic('s');
                   gridBag.setConstraints(save, c);
                   contentPane.add(save);
                   //Set constraints for the Quit button
                   c.fill = GridBagConstraints.NONE;
                   c.weightx = 1;
                   c.weighty = 0;
                   c.gridwidth = 1;
                   c.gridx = 1;
                   c.gridy = 2;
                   c.anchor = GridBagConstraints.EAST;
                   quit.setMnemonic('q');
                   gridBag.setConstraints(quit, c);
                   contentPane.add(quit);
                   //Add ActionListener to the interactive buttons on the GUI.
                   //QUIT MENU
                   menuItemQuit.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent e) {
                             quitAction();
                   //SAVE MENU
                   menuItemSave.addActionListener(new ActionListener(){
                        public void actionPerformed(ActionEvent e){
                             saveAction();
                   //QUIT BUTTON
                   quit.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent e){
                             quitAction();
                   //SAVE BUTTON
                   save.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent e){
                             saveAction();
                   //DROPDOWN LIST
                   yearDrop.dropDown.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent e){
                             listAction();
              public void listAction(){
                   System.out.println("getSelected: "+ year[yearDrop.getSelected()]);
                   tree = new Tree(c, contentPane, gridBag, (yearDrop.getSelected()+1));
                   repaint();
         I have taken out the quitAction and saveAction methods to save space.
    I would have thought creating a new Tree object over the original tree would have updated the scrollPane.
    Any ideas would be awesome.
    Thanks in advance.

    and I create a new tree object with the new year details and nothing is changed in the scrollpane.Creating a new Tree doesn't add the tree to the scroll pane. It just changes the reference of the tree variable to point to the new Tree object. To update the scroll pane you would need to do:
    scrollPane.setViewportView( tree );
    Or another option is to just create a new TreeModel and then change the model that your existing tree is using:
    TreeModel model = new TreeModel(...);
    tree.setModel( model );

  • How to find out list user who did the printing

    Dear All,
    We are using network print server using HP LaserJet 5550 and jetdirect, since our number of users is more than 500 staff in one place, sometimes they do the unresponsible printing such as print full color photos for personal use, print a novel and anything that not related to the business purpose.
    Today, our director found out that someone print out a whole story book and spend a lot of paper... he challenge me to find out who is the user who did this? I can log on to the printer web console, but I can't find user log printing...
    Any help will be much appreciated.
    Thanks & Regards,
    Franky

    This seems to be a commercial product. For the best chance at finding a solution I would suggest posting in the forum for HP Business Support!
    You can find the Commercial Jetdirect board here:
    http://h30499.www3.hp.com/t5/Print-Servers-Network​-Storage/bd-p/bsc-254
    Best of Luck!
    You can say thanks by clicking the Kudos Star in my post. If my post resolves your problem, please mark it as Accepted Solution so others can benefit too.

  • Is there a way of finding out what has been accessed on my MacBook Pro whilst in the possession of an apple authorised service centre?

    Hi Guys,
    I'm a bit new to this discussion group thing although I've been using Macintosh computers for many years (showing my age).
    I handed my MacBook Pro to be repaired at an authorised apple service centre. When I handed it in they said they needed to keep hold of it to run some diagnostics and requested my password. I've owned various models of mac for the the past 17 years and this is the first hardware problem I have encountered, hence I have never bothered to set up user accounts. 
    As I live in quite a remote part of Sweden I am paranoid that some untrusted technician is going to make a copy of my music (11,000 tracks) or share some of my personal information (scanned copies of my birth certificate, passport, certificates, photos, etc.) on the web. Is there a way of finding out what activity has taken place whilst they've had it in their possession?
    I appreciate any advice you guys can offer.
    Thanks!
    PS: I've already thought about the 'recently opened' menu and The machine in question is a MacBook Pro 17" (2011) running OS X 10.6.8 (need Rosetta).

    I am paranoid that some untrusted technician is going to make a copy of my music (11,000 tracks) or share some of my personal information (scanned copies of my birth certificate, passport, certificates, photos, etc.) on the web.
    If you put your info into the computer and hand it to another, you have to assume they will copy everything.
    Why are you putting scanned copies of valuable identity information into a computer than can be hacked, stolen, lost or compromised by a dirty tech?
    Have you lost your mind?
    Is there a way of finding out what activity has taken place whilst they've had it in their possession?
    No. The tech would just deny it if he did, or tell the truth which the answer would be "NO" in either case.
    The employer won't ask that sort of questions without solid proof, less they make a enemy of the employee and/or risk being sued for defamation of character.
    It's not like they bother to have a team of people watching over his shoulder that he doesn't stick a USB thumb drive of your data into his pocket to take home.
    I am paranoid that some untrusted technician is going to make a copy of my music (11,000 tracks)
    If it's iTunes music, it has your personal ID embedded into the song files. Most IT techs know this though.
    I appreciate any advice you guys can offer.
    Too late now, all you can do is not worry about it.
    Take your personal info out of the machine and if you need it, burn cd/dvd copies, a few USB thumb drives, Iron Keys or self encrypting external storage drives with key and/or keypad.

  • How do I find out a file's particular size?

    Good Evening,
    I am looking for assistance with figuring out a file's particular size within a group of files.
    If I have one large directory and I am looking to find out what the smallest file in that directory is, how would I go about doing it?
    Also, how would I figure out when the file was created on the system or particular hard drive such as a network attached storage device?
    Thank you!

    While command + i (or the Finder Information icon) would give you the file size, that would require a one-by-one approach. Perhaps quicker would be using a utility like "What Size" that will list Folders/files and give the size of each.

  • How do i find out who the carrier is and can i get it unlocked to use in australia?

    Hi there,
    I got a iphone4 from my friend ewho brought it from someone from ebay in the states
    I am unable to use the phone and was told that the phone had been updated to a baseband that can not be unlocked
    and that I need to contact the carrier.
    How do I find out who the carrier is and is there anyway I can get it unlocked to be used in Australia?
    It has a grevey sim in it and well at this point in time its just being used as an ipod.
    Yes I know I should of got one from Australia but i thought it wouldnt be this hard to get it fixed to be able to use here.
    please help........
    thanx
    lana

    The discussion of Jailbroken Devices is against the Terms of Use of this Forum.
    http://support.apple.com/kb/HT3743

  • How do I find out what applications are running in the background

    I have a 2008 iMac with 2GB memory.  How do I find out what programs are running in the background?  I am going to buy a new iMac before the end of the year to replace this one.  When I looked at Activity Monitor it shows 1.8Gb used but doesn't tell all the programs running.

    open activity monitor [if it doesnt launch click winders>Activity Monitor]. then it'll show all proceses

  • How do I find out how many files I have, as an earlier version of iTunes told you at the bottom of the screen. Can you please help me.

    How do I find out how many files I have, as an earlier version of iTunes told you at the bottom of the screen.
    Can anyone please help me with this so I know how many music files or video files I have in my collection.

    Have a look here...
    http://osxdaily.com/2012/11/29/5-tips-make-itunes-look-normal/

  • How to find out the user name and email address from SAP user id?

    Hi experts,
    In sto3n I find out the the user id with most navigations. I like to know his name or email address to contact him. Which table stores the user details? how to do it?
    Thanks in advance.
    Sharat.

    hi,
    The below tables will give only the name .
    USER_ADDRS
    USER_ADDR
    USER_ADDRP
    USR02
    i think you need email address .
    you can use this Tcode : su01d
    and give the user name and excute it
    i hope it will help you.
    Ram
    Edited by: Ram velanati on Jun 30, 2008 6:57 PM

  • How to find out the list of field exists for a particular transaction

    Hi all,
    Can u please help me find out the list of field exits available for a particular Tcode?
    Is it similar to User exit or . . . . ?
    Thanks,
    C.Selvaraj
    SAP-QM

    Create a program and add this code to find user exit
    tables : tstc, tadir, modsapt, modact, trdir, tfdir, enlfdir.
    tables : tstct.
    data : jtab like tadir occurs 0 with header line.
    data : field1(30).
    data : v_devclass like tadir-devclass.
    parameters : p_tcode like tstc-tcode obligatory.
    select single * from tstc where tcode eq p_tcode.
    if sy-subrc eq 0.
      select single * from tadir where pgmid = 'R3TR'
      and object = 'PROG'
      and obj_name = tstc-pgmna.
      move : tadir-devclass to v_devclass.
      if sy-subrc ne 0.
        select single * from trdir where name = tstc-pgmna.
        if trdir-subc eq 'F'.
          select single * from tfdir where pname = tstc-pgmna.
          select single * from enlfdir where funcname =
          tfdir-funcname.
          select single * from tadir where pgmid = 'R3TR'
          and object = 'FUGR'
          and obj_name eq enlfdir-area.
          move : tadir-devclass to v_devclass.
        endif.
      endif.
      select * from tadir into table jtab
      where pgmid = 'R3TR'
      and object = 'SMOD'
      and devclass = v_devclass.
      select single * from tstct where sprsl eq sy-langu and
      tcode eq p_tcode.
      format color col_positive intensified off.
      write:/(19) 'Transaction Code - ',                        "#EC NOTEXT
      20(20) p_tcode,
      45(50) tstct-ttext.
      skip.
      if not jtab[] is initial.
        write:/(95) sy-uline.
        format color col_heading intensified on.
        write:/1 sy-vline,
        2 'Exit Name',                                          "#EC NOTEXT
        21 sy-vline ,
        22 'Description',                                       "#EC NOTEXT
        95 sy-vline.
        write:/(95) sy-uline.
        loop at jtab.
          select single * from modsapt
          where sprsl = sy-langu and
          name = jtab-obj_name.
          format color col_normal intensified off.
          write:/1 sy-vline,
          2 jtab-obj_name hotspot on,
          21 sy-vline ,
          22 modsapt-modtext,
          95 sy-vline.
        endloop.
        write:/(95) sy-uline.
        describe table jtab.
        skip.
        format color col_total intensified on.
        write:/ 'No of Exits:' , sy-tfill.                      "#EC NOTEXT
      else.
        format color col_negative intensified on.
        write:/(95) 'No User Exit exists'.                      "#EC NOTEXT
      endif.
    else.
      format color col_negative intensified on.
      write:/(95) 'Transaction Code Does Not Exist'.            "#EC NOTEXT
    endif.
    at line-selection.
      get cursor field field1.
      check field1(4) eq 'JTAB'.
      set parameter id 'MON' field sy-lisel+1(10).
      call transaction 'SMOD' and skip first screen.
    Rewards if useful........................
    Minal

  • How to find out the list of patches applied without using inventory?

    Hi,
    I have been asked this question once.
    How will you find out the list of patches applied to Oracle Database Home without using commands like opatch lsinventory -detal etc...
    I think registry$history is a view from where we can find out the list of patches applied.
    But I think it will not include all the bug fixes,stand alone or one-off patches.It will mainly list out the CPU patches applied(correct me if I am wrong).
    Thanks,
    Rushi

    Hi;
    Thanks Helios,
    Your welcome
    Could you tell me how do you all senior people manage to find metalink note for almost everything?There is nothing special, For me I just make more search at metalink than googling so after sometimes you started to notice which note could be related wiht issues more clearly.. Just keep searching at metalink and focus what you are searching only.. ;)
    If you could guide me I can do it my self and stop bothering you for some silly doubts.You dont bother me and also I belive the other forum users ;) We are also learning new information wiht user questions ;)
    Regard
    Helios

  • How to find out the user iD that previously deleted?

    Hi,
    My client has deleted some user ID in SBO v2004b. HOwever, when the client did that, he forgot to "deselect" the license that granted to the users going to be deleted. What's worse, he forgot the user ID that he deleted.
    It makes the license available decrease. So, how can i find out the user ID that i previously deleted? Or any method to retrieve the correct number of license originally. ?
    Thanks for your advice

    Hi,
    Have a look at the FAQ weblog, Missing licence topic:
    /people/ibai.pea/blog/2006/07/26/sbo-faq
    Regards,
    Ibai Peñ

Maybe you are looking for

  • Delivery date field has no data in the output

    Hii I have a program like this, when I try to execute it i found no data in the Delivery date colum. Can anyone correct the code. Thanks SP Global data declaration TYPE-POOLS: slis. TABLES: vbap, vbrk, vbfa, vbak, vbrp, konv, kna1, bkpf, bsad, bkpf_b

  • PR status on a particular date..

    Gentlemen, I have to develop this Report for Procurement for the buyer monthly Performance. In this one of my requirement is to get all the PR's which were open before 1st of may..(or which ever month they like to see) How can i get these PR's..? Ple

  • Change view options for a single folder

    I use the Finder exclusively in "column view". I have a folder that contains some huge (> 1 GB) .tiff files. If I navigate to one of these files, the Finder tries to generate a preview image, but this typically takes more than a minute. I want to tur

  • How do I get events back from the trash? 10.0.3

    Trying to move some of my older projects and events to a backup drive.  I created a new library on the drive, but I could not move anything to the new project. So I copied events by dragging thme into the new library.  Then I moved the events to the

  • ADF11g: business logic in ADF BC or PLSQL?

    Hi All, For a new development in ADF 11g , where we should put our business logic: In ADF BC or in PLSQL? What if we write all the bussiness logic in plsql? Because if tomorrow ADF goes(which I know is not ging to happen soon), we can expose pl/sql a