Mouse wheel scroll on SortableTable selects rows

This forum is used by users to request and discuss new product features. Please do not use this forum for technical support including bug reports.

Moderator: JIDE Support

Forum rules
Product suggestions only. Please do not use this forum for technical support including bug reports.

Mouse wheel scroll on SortableTable selects rows

Postby aryanarvind » Thu Jul 23, 2020 7:27 am

Hello,

When you scroll within in the SortableTable using mouse wheel, the selection changes.
We have actions associated to selection change and when trying to just scroll through the table we wouldn't want to change selection but to just scroll as it's supposed to.
There are 2 problems here.
1. The mouse wheel moves the selection down.
2. The mouse wheel does not move the scroll bar down.

Please let me know if you want more details on the same.

Thanks & Regards,
Aravind Chennuru
aryanarvind
 
Posts: 108
Joined: Mon May 14, 2007 12:37 pm

Re: Mouse wheel scroll on SortableTable selects rows

Postby JIDE Support » Thu Jul 23, 2020 9:58 am

I cannot reproduce this problem in the SortableTableDemo.java using mouse wheel. Just change the row count from 8 to a large number if you want to reproduce it yourself.
JIDE Software Technical Support Team
JIDE Support
Site Admin
 
Posts: 37219
Joined: Sun Sep 14, 2003 10:49 am

Re: Mouse wheel scroll on SortableTable selects rows

Postby aryanarvind » Tue Jul 28, 2020 7:23 am

I am unable to launch the jide demos anymore.. the demo terminates, as soon as I launch it.. must be something to do with license?
aryanarvind
 
Posts: 108
Joined: Mon May 14, 2007 12:37 pm

Re: Mouse wheel scroll on SortableTable selects rows

Postby JIDE Support » Tue Jul 28, 2020 8:02 am

You download the release package and run the example project from IDEA or Eclipse. You need to modify the code so of course the demo won't work.
JIDE Software Technical Support Team
JIDE Support
Site Admin
 
Posts: 37219
Joined: Sun Sep 14, 2003 10:49 am

Re: Mouse wheel scroll on SortableTable selects rows

Postby aryanarvind » Wed Jul 29, 2020 9:56 am

Hello,

Thank you for the response. I managed to download the jide_demo.jar and copy the source code and run it from eclipse.
I realized that we are using a combination of table models.
1. SortableTableModel
2. FilterableTableModel
3. PaginationModel
The behavior of selecting the rows on mouse wheel happens on pageNavigationBar.
Is there a way to disable this feature on mouse wheel for PageNavigationBar?
As I mentioned the selection change triggers actions on various plugins and would be nice to have intentional selections like user clicks instead of Mouse Wheel when the user is just trying to scroll down to a specific region in a table.

Thanks & Regards,
Aravind Chennuru
Attachments
PageNavigationBarRowSelection.gif
PageNavigationBarRowSelection.gif (165.12 KiB) Viewed 30355 times
aryanarvind
 
Posts: 108
Joined: Mon May 14, 2007 12:37 pm

Re: Mouse wheel scroll on SortableTable selects rows

Postby JIDE Support » Wed Jul 29, 2020 12:06 pm

That explained. You can override createMouseWheelListener to return a mouse wheel listener that does nothing to prevent it.
JIDE Software Technical Support Team
JIDE Support
Site Admin
 
Posts: 37219
Joined: Sun Sep 14, 2003 10:49 am

Re: Mouse wheel scroll on SortableTable selects rows

Postby aryanarvind » Thu Jul 30, 2020 7:22 am

Hello,
In continuation, is this a bug with selection?
When I resize the table and scroll down, I see multi selection. which should not happen.
Please refer to the screenshot.


Thanks & Regards,
Aravind Chennuru
Attachments
PageNavigationBarIssue.PNG
PageNavigationBarIssue.PNG (87.13 KiB) Viewed 30347 times
aryanarvind
 
Posts: 108
Joined: Mon May 14, 2007 12:37 pm

Re: Mouse wheel scroll on SortableTable selects rows

Postby aryanarvind » Thu Jul 30, 2020 8:18 am

Hello,

This is the code that kind of replicates the issue, I have in the product, could you please help me with this weird behavior?

Code: Select all
/*
 * @(#)LargeSortableTableDemo.java
 *
 * Copyright 2002 - 2004 JIDE Software Inc. All rights reserved.
 */

import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseWheelEvent;
import java.awt.event.MouseWheelListener;

import javax.swing.AbstractAction;
import javax.swing.Box;
import javax.swing.Box.Filler;
import javax.swing.JButton;
import javax.swing.JFormattedTextField;
import javax.swing.JLabel;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.JPopupMenu;
import javax.swing.JScrollPane;
import javax.swing.JSlider;
import javax.swing.SwingUtilities;
import javax.swing.border.Border;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import javax.swing.event.TableModelEvent;
import javax.swing.event.TableModelListener;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.JTableHeader;

import com.jidesoft.converter.ObjectConverterManager;
import com.jidesoft.grid.JideTable;
import com.jidesoft.grid.SortableTable;
import com.jidesoft.grid.SortableTableModel;
import com.jidesoft.grid.TableModelWrapperUtils;
import com.jidesoft.paging.PageNavigationBar;
import com.jidesoft.plaf.LookAndFeelFactory;
import com.jidesoft.status.StatusBar;
import com.jidesoft.swing.JideBoxLayout;
import com.jidesoft.swing.JidePopupMenu;

/**
 * Demoed Component: {@link SortableTable} <br> Required jar files: jide-common.jar, jide-grids.jar <br> Required L&F:
 * any L&F
 */
public class LargeSortableTableNavBarDemo extends AbstractDemo {
    private static final long serialVersionUID = 8470522350348490198L;
    public DefaultTableModel _model;
    public SortableTable _sortableTable;
    protected JLabel _countLabel;
    protected JSlider _slider;

    public LargeSortableTableNavBarDemo() {
    }

    public static class LargeTableModel extends DefaultTableModel {

        private static final long serialVersionUID = -5456719708922578368L;

        @Override
        public Class<?> getColumnClass(int column) {
            switch (column) {
                case 0:
                    return Integer.class;
                case 1:
                    return Double.class;
                case 2:
                    return Boolean.class;
                case 3:
                    return String.class;
            }
            return Object.class;
        }
    }

    public String getName() {
        return "SortableTable Demo (Large Model)";
    }

    @Override
    public Component getOptionsPanel() {
        JPanel panel = new JPanel();
        panel.setLayout(new JideBoxLayout(panel, JideBoxLayout.Y_AXIS, 2));
        _slider = new JSlider(1, 6, 4);
        _slider.setValue((int) Math.log10(_model.getRowCount()));
        panel.add(new JLabel("Data set size (to the power of 10):"));
        panel.add(_slider);
        _countLabel = new JLabel();
        _countLabel.setText("Total row counts: " + ObjectConverterManager.toString(_model.getRowCount()));
        panel.add(_countLabel);
        _slider.setMajorTickSpacing(1);
        _slider.setPaintTrack(true);
        _slider.setSnapToTicks(true);
        _slider.setPaintTicks(true);
        _slider.setPaintLabels(true);
        _slider.setPaintTicks(true);
        _slider.addChangeListener(new ChangeListener() {
            public void stateChanged(ChangeEvent e) {
                if (!_slider.getValueIsAdjusting()) {
                    clearData();

                    final int value = (int) Math.pow(10, _slider.getValue());
                    populateTable(value);
                }
            }
        });

        panel.add(Box.createVerticalStrut(6));
        panel.add(new JButton(new AbstractAction("Insert a row") {
            private static final long serialVersionUID = -4663467797343622067L;

            public void actionPerformed(ActionEvent e) {
                int row = _sortableTable.getSelectedRow();
                if (row == -1) {
                    row = _sortableTable.getRowCount();
                }
                _model.insertRow(row, new Object[]{100000, Math.random(), Boolean.FALSE, "new row"});
                int visualRow = _sortableTable.getSortedRowAt(row);
                _sortableTable.changeSelection(visualRow, 0, false, false);
            }
        }));
        panel.add(new JButton(new AbstractAction("Delete selected rows") {
            private static final long serialVersionUID = 6583734909578856612L;

            public void actionPerformed(ActionEvent e) {
                // _sortableTable.getSelectedRows() returns the row indices after sorted,
                // so we need to convert them to the actual row indices as in the actual table model
                int[] rows = TableModelWrapperUtils.getActualRowsAt(_sortableTable.getModel(), _sortableTable.getSelectedRows(), true);
                for (int i = rows.length - 1; i >= 0; i--) {
                    int row = rows[i];
                    _model.removeRow(row);
                }
            }
        }));
        panel.add(new JButton(new AbstractAction("Delete all rows") {
            private static final long serialVersionUID = -8149334113803021585L;

            public void actionPerformed(ActionEvent e) {
                clearData();
            }
        }));

        return panel;
    }

    private void clearData() {
        int rowCount = _model.getRowCount();
        _model.getDataVector().clear();
        _model.fireTableRowsDeleted(0, rowCount - 1);
    }

    private void populateTable(int value) {
        for (int i = 0; i < value; i++) {
            _model.addRow(new Object[]{i * 1024, Math.random(), i % 2 == 0, "row" + i});
        }
    }

    @Override
    public String getDescription() {
        return "This is a demo of SortableTable with a large table model. You can adjust the slider to get a table model as many as 1 million rows.\n" +
                "\nClick once on the header to sort ascending, click twice to sort descending, a third time to unsort. Hold CTRL key then click on several headers to see multiple columns sorting. With a large table model, you can experience the performance when sorting.\n" +
                "\nTo see the dynamic update when table model changes, press the buttons in options panel.\n" +
                "\n" +
                "Demoed classes:\n" +
                "com.jidesoft.grid.SortableTable";
    }

    public String getProduct() {
        return PRODUCT_NAME_GRIDS;
    }

    public Component getDemoPanel() {
        _model = new LargeTableModel();
        _model.addColumn("int");
        _model.addColumn("double");
        _model.addColumn("boolean");
        _model.addColumn("string");
       
        _sortableTable = new SortableTable(_model);
        _sortableTable.setAutoResizeMode(JideTable.AUTO_RESIZE_FILL);
        _sortableTable.getTableHeader().addMouseListener(new MouseAdapter() {
            @Override
            public void mousePressed(MouseEvent e) {
                super.mousePressed(e);
                if (e.isPopupTrigger()) {
                    showPopup(e);
                }
            }

            @Override
            public void mouseReleased(MouseEvent e) {
                super.mouseReleased(e);
                if (e.isPopupTrigger()) {
                    showPopup(e);
                }
            }

            private void showPopup(MouseEvent e) {
                int column = ((JTableHeader) e.getSource()).getColumnModel().getColumnIndexAtX(e.getPoint().x);
                JMenuItem[] menuItems = ((SortableTableModel) _sortableTable.getModel()).getPopupMenuItems(column);
                JPopupMenu popupMenu = new JidePopupMenu();
                for (JMenuItem item : menuItems) {
                    popupMenu.add(item);
                }
                popupMenu.show((Component) e.getSource(), e.getPoint().x, e.getPoint().y);
            }
        });
       
        PageNavigationBar navBar = new PageNavigationBar(_sortableTable) {
         

//         @Override
//         protected MouseWheelListener createMouseWheelListener() {
//            return new MouseWheelListener() {
//
//               @Override
//               public void mouseWheelMoved(MouseWheelEvent e) {
//                  
//               }
//               
//            };
//         }

         private void customizeNavigationBar() {
            add(Box.createHorizontalStrut(5));
            add(new JLabel("Rows"));
            add(new JFormattedTextField());
            add(Box.createHorizontalStrut(5));
            add(Box.createHorizontalStrut(5));
            add(Box.createHorizontalStrut(5));
            setRollover(true);
            getPageNavigationSupport().setPageSize(100);
         }

         @Override
         protected void initComponents() {
            super.initComponents();
            if (getComponent(getComponentCount() - 1) instanceof Filler) {
               remove(getComponentCount() - 1);
            }
            customizeNavigationBar();
            add(Box.createGlue(), JideBoxLayout.VARY);
         }
      };
        _model.addTableModelListener(new TableModelListener() {
            public void tableChanged(TableModelEvent e) {
                if (_countLabel != null) {
                    _countLabel.setText("Total row counts: " + ObjectConverterManager.toString(_model.getRowCount()));
                }
            }
        });

        _sortableTable.setPreferredScrollableViewportSize(new Dimension(550, 400));
        populateTable(10000);
       
        JPanel panel = new JPanel();
        panel.setLayout(new BorderLayout());
        panel.add(new JScrollPane(_sortableTable), BorderLayout.CENTER);
        panel.add(navBar, BorderLayout.SOUTH);
        return panel;
    }

    @Override
    public String getDemoFolder() {
        return "G3.LargeSortableTable";
    }

    static public void main(String[] s) {
        SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                LookAndFeelFactory.installDefaultLookAndFeelAndExtension();
                showAsFrame(new LargeSortableTableNavBarDemo());
            }
        });

    }
}

aryanarvind
 
Posts: 108
Joined: Mon May 14, 2007 12:37 pm

Re: Mouse wheel scroll on SortableTable selects rows

Postby JIDE Support » Thu Jul 30, 2020 9:46 am

I ran your code but didn't notice any multiple selections. What exactly did you do? I select, resize, and wheel scroll.
JIDE Software Technical Support Team
JIDE Support
Site Admin
 
Posts: 37219
Joined: Sun Sep 14, 2003 10:49 am

Re: Mouse wheel scroll on SortableTable selects rows

Postby aryanarvind » Thu Jul 30, 2020 10:15 am

Those are 2 different problems.
The code I sent reproduces the problem when I use mouse wheel the table does not scroll. This is using both sortableTable with PageNavigationBar.

The other one, we don't need a code, you can reproduce that in there...
1. Resize the table to get smaller.
2. Scroll in the table using mouse wheel
3. Resize the table to grow bigger.
4. You can see multiple selections.
aryanarvind
 
Posts: 108
Joined: Mon May 14, 2007 12:37 pm

Re: Mouse wheel scroll on SortableTable selects rows

Postby JIDE Support » Thu Jul 30, 2020 10:41 am

Just remove the mouse wheel listener we added.

Code: Select all
            protected void initComponents() {
                 ...
                MouseWheelListener[] mouseWheelListeners = _sortableTable.getMouseWheelListeners();
                _sortableTable.removeMouseWheelListener(mouseWheelListeners[0]);
            }


I still don't see the second issue with or without the change I just mentioned. Please make sure it is not an issue because of your own code.
JIDE Software Technical Support Team
JIDE Support
Site Admin
 
Posts: 37219
Joined: Sun Sep 14, 2003 10:49 am

Re: Mouse wheel scroll on SortableTable selects rows

Postby aryanarvind » Thu Jul 30, 2020 10:55 am

Thank you, this works really good.. Appreciate the help.
aryanarvind
 
Posts: 108
Joined: Mon May 14, 2007 12:37 pm

Re: Mouse wheel scroll on SortableTable selects rows

Postby aryanarvind » Thu Jul 30, 2020 10:58 am

Here is a gif demonstrating the issue.
https://gifyu.com/image/WV2o
aryanarvind
 
Posts: 108
Joined: Mon May 14, 2007 12:37 pm

Re: Mouse wheel scroll on SortableTable selects rows

Postby JIDE Support » Thu Jul 30, 2020 11:40 am

I am running it as a separate demo and I don't see the issue. Then I reproduce it using JideDemo and run as a nested demo. Do you see it in your real application?
JIDE Software Technical Support Team
JIDE Support
Site Admin
 
Posts: 37219
Joined: Sun Sep 14, 2003 10:49 am

Re: Mouse wheel scroll on SortableTable selects rows

Postby aryanarvind » Thu Jul 30, 2020 12:33 pm

Yes, looks like this is reproducible in a dockable.
aryanarvind
 
Posts: 108
Joined: Mon May 14, 2007 12:37 pm

Re: Mouse wheel scroll on SortableTable selects rows

Postby JIDE Support » Thu Jul 30, 2020 2:03 pm

I will fix it. If you want to fix it in your code for now, please override as below.

Code: Select all
            @Override
            protected void setSelectedRecordIndex(int row) {
                _sortableTable.getSelectionModel().clearSelection();
                _sortableTable.getSelectionModel().setSelectionInterval(row, row);
            }
JIDE Software Technical Support Team
JIDE Support
Site Admin
 
Posts: 37219
Joined: Sun Sep 14, 2003 10:49 am

Re: Mouse wheel scroll on SortableTable selects rows

Postby aryanarvind » Mon Aug 03, 2020 7:35 am

Thanks, that works really good.
aryanarvind
 
Posts: 108
Joined: Mon May 14, 2007 12:37 pm


Return to Product Suggestions

Who is online

Users browsing this forum: No registered users and 6 guests

cron