Results 1 to 12 of 12
  1. #1
    kumar_gemi is offline Member
    Join Date
    Oct 2008
    Posts
    21
    Rep Power
    0

    Default jscrollpane scroll issues

    Hi,

    I am drawing some vertical and horizontal lines which is some type of a graph. There are a large number of nodes. It works fine but my problem is when I try to move the scrollbar it takes a long time to draw. Can someone give me some advise regarding this.

    I am creating a jpanel and adding it to the jscollpane's viewport.

    Thanks in advance

    regards
    gemi

  2. #2
    StormyWaters is offline Senior Member
    Join Date
    Feb 2009
    Posts
    306
    Rep Power
    6

    Default

    Try disabling the drawing of the JPanel until the scrolling is complete. I ran into the same problem except I was using the JScrollPane to display drawings on a JLabel.

    I added a check inside my draw method to make sure the JScrollPane isn't currently being scrolled before drawing the complicated objects.

  3. #3
    camickr is offline Senior Member
    Join Date
    Jul 2009
    Posts
    1,236
    Rep Power
    7

    Default

    Draw to a BufferedImage instead of directly to the panel. See "Custom Painting Approaches":

    tips4java.wordpress.com/2009/05/08/custom-painting-approaches

  4. #4
    kumar_gemi is offline Member
    Join Date
    Oct 2008
    Posts
    21
    Rep Power
    0

    Default

    Thankyou for all the replies. But I am not drawing any image. I am using g.drawline(x1,y1,x2,y2) to draw these different lines. Can someone explain me with some code.

    I am using netbeans IDE and I am trying to create a custom jpanel which overrides the paintcomponent and then I add it over the jscrollpane. As said above I am also not sure how to call the repaint method only after the scroll event is triggered.

    Thanks

  5. #5
    camickr is offline Senior Member
    Join Date
    Jul 2009
    Posts
    1,236
    Rep Power
    7

    Default

    Can someone explain me with some code.
    I did explain with code.

  6. #6
    kumar_gemi is offline Member
    Join Date
    Oct 2008
    Posts
    21
    Rep Power
    0

    Default

    Thanks camickr for your reply. But its for buffered image.

  7. #7
    camickr is offline Senior Member
    Join Date
    Jul 2009
    Posts
    1,236
    Rep Power
    7

    Default

    Yes, that is the point. The paintComponent() method is called multiple times, especially when scrolling is done. So when you have complex painting code, its better to do it once to a BufferedImage and then just have the paintComponent() method paint the BufferedImage. Then you should not have a problem with scrolling because the paintComponent() method is now very simple.

  8. #8
    kumar_gemi is offline Member
    Join Date
    Oct 2008
    Posts
    21
    Rep Power
    0

    Default

    Thanks camickr for your reply. I am still working on it. I have do a lot of changes as I do have a zoom and slider function. I also have another doubt. I do have a filter button which filters the number of vertical lines to be displayed. I am confused on how to dynamically change the BufferedImage as its used as static and not dynamic...

    Once again thankyou for all the replies.

    Regards
    gemi

  9. #9
    camickr is offline Senior Member
    Join Date
    Jul 2009
    Posts
    1,236
    Rep Power
    7

    Default

    You can recreate the BufferedImage at any time. All you are trying to do is remove the painting from the paintComponent() method so that it is only executed, once when something about the image changes.

  10. #10
    kumar_gemi is offline Member
    Join Date
    Oct 2008
    Posts
    21
    Rep Power
    0

    Default

    Hello Camickr

    I am getting an "Exception in thread "AWT-EventQueue-0" java.lang.OutOfMemoryError: Java heap space" error message as the image size is very large.....

  11. #11
    kumar_gemi is offline Member
    Join Date
    Oct 2008
    Posts
    21
    Rep Power
    0

    Default

    Hello Camickr

    Thankyou for your advise.....I even tried increasing the netbeans JVM to increase the heapsize and its not working...Even I tried to split the buffered image into different parts but no go.

    I got another idea of just drawing only those lines which are visible to the jviewport but can u give me some guidance on how to draw only the visible area.

  12. #12
    camickr is offline Senior Member
    Join Date
    Jul 2009
    Posts
    1,236
    Rep Power
    7

    Default

    can u give me some guidance on how to draw only the visible area.
    That is done automatically by the paintComponent() method. If you look at the "clip bounds" of the Graphics Object is will specify only the area that needs to be repainted. The problem is your code recreating the entire drawing from scratch which is why I suggested using a buffered image. I don't know how to get around the size issue.

    I can't make any specific suggestions because I don't know what your painting is doing. You can try looking at Text Component Line Number for an example of using the above approach. The paintComponent() method uses the clip bounds to limit the amount of painting that is done.

Similar Threads

  1. smooth-scroll
    By designer in forum Java Applets
    Replies: 1
    Last Post: 07-21-2009, 08:10 PM
  2. problem with scroll bar
    By r.gnanaprakasam in forum AWT / Swing
    Replies: 0
    Last Post: 04-22-2009, 02:24 PM
  3. Scroll message
    By getkiran in forum Java Applets
    Replies: 1
    Last Post: 03-05-2009, 05:29 AM
  4. code hint scroll bar ?
    By tryit in forum Eclipse
    Replies: 3
    Last Post: 04-28-2008, 08:07 AM
  5. Jtextarea and scroll
    By ziniestro in forum AWT / Swing
    Replies: 2
    Last Post: 06-01-2007, 04:59 PM

Posting Permissions

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