SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Evangelist jkh1978's Avatar
    Join Date
    May 2001
    Location
    Northern Virginia
    Posts
    445
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    java JScrollPane problem

    I have an application that uses the JScrollPane. With version 1.2.2 of the jre, i could click on elements contained in the panes and the JScrollPane worked fine. Now that I am using jre 1.3, the JScrollPane moves to the left to position 143 everytime I click on an element of the JScrollPane. What could be the difference? Is our code going to be needed to change?

  2. #2
    SitePoint Evangelist jkh1978's Avatar
    Join Date
    May 2001
    Location
    Northern Virginia
    Posts
    445
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The problem occurs when a element of a tree is clicked that is in the left pane of the JScrollPane.

    The tree is a class we wrote that extends JScrollPane and implements TreeSelectionListener, TreeExpansionListener, and MouseListener

    The constructor calls a build method, and that build method contains:

    //code to build nodes...
    m_tree.addTreeExpansionListener(this);
    m_tree.addTreeSelectionListener(this);
    m_tree.addMouseListener(this);
    setViewportView(m_tree);
    }

    if I comment out
    m_tree.addTreeSelectionListener(this);
    m_tree.addMouseListener(this);
    then the scroll pane does not reset, but I do not get the action to occur that I want. Any ideas what I should be looking for?

  3. #3
    SitePoint Evangelist jkh1978's Avatar
    Join Date
    May 2001
    Location
    Northern Virginia
    Posts
    445
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    it works - why?

    I found the problem... in the code where:

    ((JSplitPane)m_MainArea).remove(m_WorkSpace);
    ((JSplitPane)m_MainArea).setRightComponent(workspace);

    it was changing the location of the divider, but if I added:

    ((JSplitPane)m_MainArea).setDividerLocation(((JSplitPane)m_MainArea).getDividerLocation());

    then it worked fine. Why would I need to add this line?

  4. #4
    Are you ready for BSD? Marshall's Avatar
    Join Date
    Dec 2001
    Posts
    373
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The remove() call before setRightComponent() is unnecessary and probably the cause of your problem. If a right Component already exists when the setRightComponent() method is called JSplitPane automatically removes the existing component before adding the new one. By calling the remove() method directly you're forcing the screen to be redrawn with no right Component assigned, which is probably what results in your divider values being changed.

    I highly recommend that you download the source code for Sun's Java classes. It's very useful in diagnosing situations such as this one :-)


    - Marshall


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •