简体   繁体   中英

How can I make JScrollBar take a long values in the constructor?

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?

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.

我可能会尝试JScrollBar并重写setValue并相应地调整(缩放)该值。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM