Jtables Simultaneos

Asked

Viewed 65 times

1

Hi, I was wondering if there’s a way to select 2 Jtables simultaneously, I’ll 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 do this directly, so I will have to do a gambiarra and leave 2 Jtables Simultaneos working in the same Model.

however, when selecting, I see that I will need to select the 2 Jtables (since the scrollbar of the vertical will be simultaneous) to show the user with which record he is moving.

if anyone knows how to do this, select the second table, but leaving the focus on the first, I appreciate

or if someone knows how to leave a particular column independent of a scrollbar, I also appreciate it, as it would make it much easier!

  • What do you mean? You want when selecting a row in one table to select the same row in the other? They have the same amount of data?

  • yes, they do have the same amount of data, I will explain better: the table I am working on is point card, where there is date, day week, off, holiday, entries and exits, and total, but the entries and exits are dynamic, ie, may have more or less, If the scrollpane gets larger than the screen, it should only move from the first entry forward, leaving fixed the other columns, so I will separate into 2 tables, but anyway, yes, they have the same amount of data! If you know a simpler way than this scam, I’d appreciate it.:D

  • Are you wanting to do something similar to the header of excel sheets, where the first line stays fixed while the others move in the scroll? I don’t think it’s possible to do this using Jtable.

  • That’s right, but instead of lines, do it with fixed columns, you know? and yes, there is, one way is to divide the table into 2 and, add the scrollpane of the horizontal only in 1 of the tables, while the other stays fixed, independent of the horizontal scroll, while I leave the vertical scroll of the 2 Simultaneos, as in this topic: http://stackoverflow.com/questions/12060587/how-to-scroll-two-or-more-jtables-with-a-single-scrollbar!

  • Can you exemplify how your tables work with some figure? I think I’m beginning to understand how to solve.

  • example 1: http://prntscr.com/b5ko7e example 2: http://prntscr.com/b5knwl I made this little printout in excel, note that the first 4 columns do not move in example 2, where the "Holiday" column is "overwriting" the additional column, the system has to work the same way, system print (without fixed columns): http://prntscr.com/b5kpf7 on my system, note that I even have the "Holiday" column that does not contain time (HH:mm) and, these columns serve for the user to locate inside the application, so I need it to be fixed as in the examples, if you need a better one, let me know :) Thanks!

Show 1 more comment

1 answer

0


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

The only problem is that it has a small Delay to select the other table when selecting the first.

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) {
        }

    });

Browser other questions tagged

You are not signed in. Login or sign up in order to post.