|
|
Re: Custom Scrollbar Mousewheel Support [message #1807745 is a reply to message #1807743] |
Fri, 07 June 2019 08:23 |
Niklas Kellner Messages: 5 Registered: March 2019 |
Junior Member |
|
|
Hello Dirk,
I did not use the FlatScrollBar I used the SWT Slider Widget. My Viewport is split Horizontal and the Vertical Scrollbar drawn by the NatTable works with the mousewheel. I did not test if the SWT Sliders works with a nattable without split, but i will do this.
I did add this external Scrollbar to achive that the Scrollbar is always visible, I tried it with the SWT.V_SCROLL style Flag but then the Bottom Scrollbar did no longer work and there where some other problems with the split viewport.
Edit: I just tried it without the split viewport, i also does not work with the mouse wheel and only with mouse draging
[Updated on: Fri, 07 June 2019 09:37] Report message to a moderator
|
|
|
Re: Custom Scrollbar Mousewheel Support [message #1814075 is a reply to message #1807745] |
Tue, 03 September 2019 06:35 |
Dirk Fauth Messages: 2903 Registered: July 2012 |
Senior Member |
|
|
I checked again and found out that it seems to be an issue with the Slider. Unfortunately it does not get a SWT selection event on mousewheel, and it also does not fire a selection event when setting the selection via setSelection().
I was able to add the mousewheel support manually with the following code which sets the selection programmatically on mousewheel events and then perform actions that would normally done automatically by the ScrollBarHandlerTemplate which is a listener on SWT.Selection events.
ViewportLayer viewportLayer = new ViewportLayer(bodyDataLayer);
Composite composite = new Composite(parent, SWT.NONE);
GridLayout gridLayout = new GridLayout(2, false);
gridLayout.marginHeight = 0;
gridLayout.marginWidth = 0;
gridLayout.horizontalSpacing = 0;
gridLayout.verticalSpacing = 0;
composite.setLayout(gridLayout);
NatTable natTable = new NatTable(composite, viewportLayer);
GridDataFactory.fillDefaults().grab(true, true).applyTo(natTable);
Slider slider = new Slider(composite, SWT.VERTICAL);
SliderScroller scroller = new SliderScroller(slider);
viewportLayer.setVerticalScroller(scroller);
GridDataFactory.defaultsFor(slider).align(SWT.BEGINNING, SWT.FILL).grab(false, true).applyTo(slider);
natTable.addListener(SWT.MouseWheel, new Listener() {
@Override
public void handleEvent(Event event) {
if (event.stateMask == SWT.MOD2) {
ScrollBar horizontal = natTable.getHorizontalBar();
// update the selection
horizontal.setSelection(horizontal.getSelection() -
((event.count < 0 ? -1 : 1) * horizontal.getIncrement()));
// perform selection handling
viewportLayer.setOriginX(viewportLayer.getMinimumOrigin().getX() + horizontal.getSelection());
int increment = viewportLayer.getColumnCount() > 0 ? viewportLayer.getColumnWidthByPosition(0) : 0;
int scrollIncrement = Math.min(increment, viewportLayer.getClientAreaWidth() / 4);
horizontal.setIncrement(scrollIncrement);
} else {
// update the selection
slider.setSelection(slider.getSelection() -
((event.count < 0 ? -1 : 1) * slider.getIncrement()));
// perform selection handling
viewportLayer.setOriginY(viewportLayer.getMinimumOrigin().getY() + scroller.getSelection());
int increment = viewportLayer.getRowCount() > 0 ? viewportLayer.getRowHeightByPosition(0) : 0;
int scrollIncrement = Math.min(increment, viewportLayer.getClientAreaHeight() / 4);
scroller.setIncrement(scrollIncrement);
}
event.doit = false;
}
});
[Updated on: Tue, 03 September 2019 07:57] Report message to a moderator
|
|
|
Powered by
FUDForum. Page generated in 0.03417 seconds