2

So there is a constructor for JScrollBar that looks like:

public JScrollBar(int orientation, int value, int extent, int min, int max) 

For my implementation of JScrollBar I need to have the int values be long since the size of my data can be over int's limitations, so something like:

public JScrollBar(int orientation, long value, long extent, long min, long max) 

What is the best way for me to implement this constructor for JScrollBar, would it be to completly remake JScrollBar, since those values are everywhere? Or is there some other way much better way to do this.

NOTE: If I do completely rewrite JscrollBar I will also have to overwrite swing.DefaultBoundedRangeModel too because it also takes an int. This doesn't seem to be the best approach so does anyone have any better ideas?

Grammin
  • 11,808
  • 22
  • 80
  • 138

2 Answers2

3

At some level you are going to run out of screen resolution in order to properly detect actual changes. Either you'll scroll the content, and the scrollbar won't move. Or, the user will move the scrollbar at be teleported to a new area creating a disorientation.

A 32 bit integer runs up is 2 billion positive numbers. If you screen resolution is even 1,000 pixels the user won't be able to control a scrollbar because ever pixel movement on the scroll bar would represent 2,147,483 pixels in the destination of whatever you're scrolling (if your zoom is 1:1). So I'd probably think of a way to map a zoom level onto the scroll bar so that you can scroll at any level and it will be smooth.

Other options might be to use an overview/detail control that shows a small picture with a square showing where you are in the bigger image, then a zoomed in display. You can drag the picture in the upper image and see it's results in the detailed image. The issues there are that you still have this 2 Million pixel movement if you move it just a pixel so it will be quite disorienting to move around an image that big at small zoom scales. But, use the hand dragging in the detail view for smaller movements that aren't as disorientating. That side steps the issue of reimplementing JScrollBar and probably will be better option.

chubbsondubs
  • 37,646
  • 24
  • 106
  • 138
  • 1
    I'm buffering in a bunch of data so say the range is from 1 - 100 and they are at position 56; if they click down on the scroll bar it will be at position 57 not the graphical representation of where the scrollbar would go down to... I hope that makes sense? – Grammin Oct 27 '11 at 19:18
  • Sounds like you're just trying to create a zoomable control mapping, but in kinda strange way. If you use the scrollbar and it's 1000 positions (i.e. the scrollbar is 1000 pixels wide or high) then each pixel the thumb is moved would represent 2 Million pixels, if the scrollbar covers the far left hand side to the far right side of your scrollable. Otherwise you can't navigate the full image left to right. I think out of practicality you're going to need to create the concept of zooming in and out and scrolling with the zoom level to navigate the space effectively. – chubbsondubs Oct 27 '11 at 19:44
  • I agree with you that each scrollbar pixel move would represent 2mp, but I can click the scroll arrow on the far right and not move the scrollbar but still move the data. And thus adjust my scrollbar value without moving the actual scrollbar. – Grammin Oct 27 '11 at 20:08
  • Yea so you have two speeds: Teleporting and walking. Somewhat extreme navigation for a space as large as you are describing. :-) I guess my point is that having more resolution to scroll within isn't going to help you navigate the space any better. – chubbsondubs Oct 27 '11 at 21:18
  • I now gotten interested in what you are doing. The more I think on how vastly large these numbers are I find myself trying to guess what you're trying to display. I keep thinking it has to be satellite images possibly. – chubbsondubs Oct 27 '11 at 21:30
1

I would probably try to subclass JScrollBar and override setValue and adjust (scale) the value accordingly.

aioobe
  • 413,195
  • 112
  • 811
  • 826