Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Programmatically Scroll an SWT Table horizontally

Tags:

java

swt

Similar question, but not exactly the same.

table.showColumn() is helpful, but the scrolling only has the granularity of the column width. But I want a more precise control of the scroll location.

Consider the following use case. I have two tables that I know are of the same width and have the same column widths. And I want to implement some kind of a scroll synchronizer so that when the user scrolls one table (horizontally), the other table scrolls to the same location.

EDIT:

On the Eclipse forum there seems to be the same question and some working ideas, but no resolution.

EDIT: I discovered this behavior on Windows

like image 533
RAY Avatar asked Nov 23 '10 08:11

RAY


3 Answers

I'm afraid I can't get a satisfying result in Windows Vista/7 either, but felt I was getting close.

I believe you will have to grab the Table's horizontal scroll bar by using table.getHorizontalBar(). Then, you can specify scrollbar.setSelection() to make it move to a specified position.

This is where I get stuck. Somehow, you have to notify either the Table or the ScrollBar that the value has changed. I've tried everything from update() to notifyListener(), but no dice. It seems that it is merely a matter of laying out, but layout() doesn't have any effect, either.

Incidentally, bear in mind that the ScrollBar's parent (type Scrollable) is not a ScrolledComposite like I had expected, but is actually the Table itself.

I hope this gives you some ideas and helps you find a solution. If so, please let me know, since it's bugging me now, too!

like image 167
Paul Lammertsma Avatar answered Nov 09 '22 02:11

Paul Lammertsma


The method setOrigin(x,y) in ScrolledComposite should help:

Scrolls the content so that the specified point in the content is in the top left corner. If no content has been set, nothing will occur. Negative values will be ignored. Values greater than the maximum scroll distance will result in scrolling to the end of the scrollbar.

like image 33
dac2009 Avatar answered Nov 09 '22 02:11

dac2009


Having poked around in the ScrollBar source a bit, it looks like there are numerous (windows) bugs that have been overcome at one point or another. This may be another, though you didn't mention your OS, nor did Paul, so it's hard to tell.

All the "change the scroll bar position" functions end up calling SetScrollInfo which is package private. I suspect that the intention is for this to actually update things the way you want.

None of that solves your problem. Thankfully the same source also hints at a solution:

Slider.

You'd have to reimplement all the scrollbar behavior within slider, but once done, that should give you the control (har) you want. Hopefully. OTOH, you may run into exactly the same OS bug (if bug it be), and be back at square one.

At THAT point, you definitely register it as an Eclipse UI bug.

PS: Have you searched the Eclipse Bugzilla for anything similar? Poking around a bit turned up this bug related to the scroll bar being out of sync with a tree view in the Navigator (on PC Linux-Motif, but working fine in Windows). I suspect you'll find similar issues if you dig a bit more.

like image 35
Mark Storer Avatar answered Nov 09 '22 00:11

Mark Storer