Simultaneous JTables

1

Hello, I would like to know if there is a way to select 2 JTables simultaneously, I will explain:

I need some columns of my JTable, do not change when the horizontal JScrollBar is changed, according to my research, there is no way I can do this directly, so I have to do a trick and leave 2 simultaneous JTables working in the same Model .

However, at the time of selecting, I see that I will need to select the 2 JTables (since the vertical scrollbar will be simultaneous) to show the user which record is moving.

If anyone knows how to do this, select the second table, but leaving focus on the first one, I thank

Or if someone knows how to leave certain column independent of a scrollbar, I also thank you, as it would make it much easier!

    
asked by anonymous 16.05.2016 / 15:41

1 answer

0

I was able to solve the problem using MouseListener in the 2 tables:

The only problem is that you have a small Delay to select the other table when you select the first one.

tb2.addMouseListener(new MouseListener() {
        @Override
        public void mouseReleased(MouseEvent e) {
            row = tbFin.getSelectedRow();
            col = tbFin.getSelectedColumn();
            tb2.setRowSelectionInterval(row, row);
            tb2.setColumnSelectionInterval(col, col);
            tb1.setRowSelectionInterval(row, row);
        }

        @Override
        public void mouseClicked(MouseEvent e) {
        }

        @Override
        public void mousePressed(MouseEvent e) {
        }

        @Override
        public void mouseEntered(MouseEvent e) {
        }

        @Override
        public void mouseExited(MouseEvent e) {
        }
    });

    tb1.addMouseListener(new MouseListener() {
        @Override
        public void mouseClicked(MouseEvent e) {
            row = tbIn.getSelectedRow();
            col = tbIn.getSelectedColumn();
            tb1.setRowSelectionInterval(row, row);
            tb1.setColumnSelectionInterval(col, col);
            tb2.setRowSelectionInterval(row, row);
        }

        @Override
        public void mousePressed(MouseEvent e) {
        }

        @Override
        public void mouseReleased(MouseEvent e) {
        }

        @Override
        public void mouseEntered(MouseEvent e) {
        }

        @Override
        public void mouseExited(MouseEvent e) {
        }

    });
    
24.05.2016 / 18:41