Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » NatTable » Custom Scrollbar Mousewheel Support
Custom Scrollbar Mousewheel Support [message #1807736] Fri, 07 June 2019 05:53 Go to next message
Niklas Kellner is currently offline Niklas KellnerFriend
Messages: 5
Registered: March 2019
Junior Member
Hello,

I have the following problem, I have a split Viewport in my table and have added custom scrollbars for both directions following this blogpost:
http://blog.vogella.com/2015/01/26/nattable-with-custom-scrollbars/

Now with this custom scrollbars i have no mousewheel support, i have tried it with an mouse wheel listener directly on the nat table and setSeletion on the Slider Widget, the effect from this is that only the slider moves and not the table. When i move the Slider with the mouse it works like it is supposed to.

Has anybody an idear how i could fix this?
Re: Custom Scrollbar Mousewheel Support [message #1807743 is a reply to message #1807736] Fri, 07 June 2019 08:10 Go to previous messageGo to next message
Dirk Fauth is currently offline Dirk FauthFriend
Messages: 2902
Registered: July 2012
Senior Member
It is quite a long time ago since I wrote that blog post and tested the FlatScrollBar. So hard to tell where the issue might be. Especially because you are directly mixing two non-trivial features.

I would suggest that you first verify that mousewheel support is working correctly with the default scrollbars in a split viewport. IIRC there you also need to attach scrollbars from the outside similar to a custom scrollbar. If that works I would verify if mousewheel support works with the FlatScrollBar in a default NatTable (non-split-viewport) to check if the issue maybe is in the scrollbar implementation. This might help in narrowing down to where the issue is.
Re: Custom Scrollbar Mousewheel Support [message #1807745 is a reply to message #1807743] Fri, 07 June 2019 08:23 Go to previous messageGo to next message
Niklas Kellner is currently offline Niklas KellnerFriend
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 Go to previous message
Dirk Fauth is currently offline Dirk FauthFriend
Messages: 2902
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

Previous Topic:How to correctly register an Action on the GridRegion.Body Mouse.RMB
Next Topic:NatTable 1.6.0
Goto Forum:
  


Current Time: Sat Apr 20 06:00:52 GMT 2024

Powered by FUDForum. Page generated in 0.03194 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top