0

I have a GUI that has multiple tables each in its own tab. Each table is configured to only allow single selections and to clear its selection when another tab is clicked. I have a delete button that deletes a selected row. I tried using isVisible() to determine which table was being displayed but it seems to regard all tables as visible. I need a way to find out which table either has a selected row, or which table is visible to the user (as in which tab is open).

Here is an example of my incorrect method:

if(jtblSunLessons.isVisible()){
            Day = "Sunday";
            startTime = jtblSunLessons.getValueAt(jtblSunLessons.getSelectedRow(), 0).toString();
        }
        else if(jtblMonLessons.isVisible()){
            Day = "Monday";
            startTime = jtblMonLessons.getValueAt(jtblMonLessons.getSelectedRow(), 0).toString();
        }
        else if(jtblTuesLessons.isVisible()){
            Day = "Tuesday";
            startTime = jtblTuesLessons.getValueAt(jtblTuesLessons.getSelectedRow(), 0).toString();
        }

Column 0 is the starting time of a lesson. Day and startTime are strings. Thanks!

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
  • The MouseListener methods' MouseEvent parameters have a `getSource()` method which should return the clicked-on component and this should allow you to find out which JTable was clicked. If this does not work for you, then you will want to create and post your [mre] code with your question. Please check out the details within the link. – Hovercraft Full Of Eels Jul 05 '20 at 14:14
  • @HovercraftFullOfEels Hi, thanks so much for your reply. I tried isShowing and it worked, do you think that's fine? – Gavriel Cohen Jul 05 '20 at 14:34
  • 1
    *I tried isShowing and it worked, do you think that's fine?* - I would suggest no. Anytime you have nested if / else statements like that you have a design problem. What if you had 100 tables, would you code 100 if statements. There is a better way, but you have not provided enough information for us to suggest a better way. You were asked to post a [mre] in your last question. Without an "MRE" we can't really tell what you are doing. – camickr Jul 05 '20 at 14:47
  • @camickr Don't worry about it, my teacher said its fine because it is a school project. Thank you so much for your help, I really appreciate it :) – Gavriel Cohen Jul 05 '20 at 14:53

0 Answers0