Results 1 to 8 of 8
Like Tree1Likes
  • 1 Post By Tolls

Thread: "Virtual" JScrollPane?

  1. #1
    jeff2365 is offline Member
    Join Date
    Aug 2011
    Posts
    4
    Rep Power
    0

    Default "Virtual" JScrollPane?

    I'd like to create a scroll pane that doesn't actually move the scrollable client object around. The client object remains fixed in place, but has a custom paint method that uses the positions of the scroll bars.

    Does anyone have any suggestions on how to implement this?

    I tried overriding setBounds(x,y,width,height) on the client object to setBounds(0,0,width,height), but while it keeps the client object from moving around, it also keeps the scroll bars from moving as well. (You can drag them, but they snap back to the original position when you let go)

    Thanks.

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,189
    Rep Power
    19

    Default

    Exactly as posted, this requirement doesn't make sense to me. Perhaps you would like to elaborate on the use case?

    Making the very big assumption that there isn't a better way to fulfill the need, I would go for two JScrollBars in the EAST and SOUTH of a BorderLayout, thus (nearly, if you don't look too closely at the bottom right corner) emulating the appearance of a JScrollPane.

    Or using a GridBagLayout with appropriate weightx / weighty could probably achieve an identical appearance to a JScrollPane.

    db

  3. #3
    jeff2365 is offline Member
    Join Date
    Aug 2011
    Posts
    4
    Rep Power
    0

    Default

    I would like to scroll JOGL's GLCanvas (so I adjust the view transforms based on the scroll bar positions). I wouldn't want to scroll the canvas itself, since that doesn't make sense, and it draws over all other components anyway.

    I was just hoping to avoid managing the scrollbars manually.

  4. #4
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,189
    Rep Power
    19

    Default

    it draws over all other components anyway.
    Starting from some recent update (6u10?) mixing heavyweight and lightweight components is supposed to no longer be a problem. Haven't tested that myself, as I don't use any heavyweight components.

    db

  5. #5
    jeff2365 is offline Member
    Join Date
    Aug 2011
    Posts
    4
    Rep Power
    0

    Default

    I'm using Java 7. It's possible that its not a heavy/lightweight issue, and has something to do with it using OpenGL to draw.

    Either way, it doesn't really matter because it would be wasteful/impractical to create a backbuffer covering the entire scrollable area, instead of just the viewport area.

    Looks like I might just need to implement this myself?

  6. #6
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,450
    Rep Power
    18

    Default

    Sadly I don't have the code handy, but I did work on a Swing system where the table displayed used a scrollbar to indicate how many rows were "returned" from the db. We didn't return all the data, but only brought back three screenfuls (visible, screen above and screen below) and fetched new rows as needed, as the scrollbar scrolled around.
    Pretty sure it was just a JScrollBar, and not some funky JScrollPane.
    I don't think the wiring was all that complicated to get it to work.

  7. #7
    jeff2365 is offline Member
    Join Date
    Aug 2011
    Posts
    4
    Rep Power
    0

    Default

    It's slightly more complicated with 2 scrollbars, since you have to worry about the corner square when both scrollbars are visible, and when one scrollbar becomes visible, it might shrink the view enough that the other one would have to become visible as well.

    I guess I'll just have to implement it myself.

    Thanks.

  8. #8
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,450
    Rep Power
    18

    Default

    Keep them both visible all the time.
    Solves that problem.
    DarrylBurke likes this.

Similar Threads

  1. Replies: 0
    Last Post: 06-24-2011, 08:14 PM
  2. Replies: 3
    Last Post: 10-12-2010, 04:21 PM
  3. Replies: 1
    Last Post: 01-21-2010, 09:20 AM
  4. Replies: 2
    Last Post: 01-24-2009, 06:56 PM
  5. Replies: 1
    Last Post: 10-20-2008, 07:35 AM

Posting Permissions

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