How can i check to see if a row has been selected?

user3747557

I have a button click event on which i am getting a column value, if a Table row is selected. But if i don't select the row and click the button i get the error: java.lang.ArrayIndexOutOfBoundsException:-1 my question is how can i check to see if a row has been selected pseudocode: if(Row == selected) { execute }

java code i have:

private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {                                         
        try 
        {
            int row = Table.getSelectedRow();
            String Table_click = (Table.getModel().getValueAt(row, 0).toString());            

           //... implementation hire   

        } catch (Exception e) 
        {
            JOptionPane.showMessageDialog(null, e);
        }        
    }  

Thank you for your help.

MarsAtomic

Stop and think logically about your problem before you're tempted to post. Take a break from coding if you need to -- once you take a break, the solution to the problem often presents itself in short order.

int row = Table.getSelectedRow();

if(row == -1)
{
    // No row selected
    // Show error message
}
else
{
    String Table_click = (Table.getModel().getValueAt(row, 0).toString());
    // do whatever you need to do with the data from the row
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How can I check if jcombobox selection has not been selected?

From Dev

How can I see when package has been upgraded?

From Dev

How can I check if an appearance property has been set?

From Dev

How can I check if an anonymous function has been called with NSubstitute?

From Dev

How can I check if file has been downloaded in ansible

From Dev

How can I check if a bean has been loaded by springboot

From Dev

How can i check the radiobutton that it has been checked in this table?

From Dev

How can I check to see if a gif animation has completed

From Dev

How do I check which JNLP file that has been selected to run?

From Dev

How do I check if a file has been selected in a <input type="file"> element?

From Dev

OpenFileDialog - Check if has not been selected

From Dev

JqGrid check to see if the row is selected

From Dev

How can I see where Ubuntu has been installed on my HDD?

From Dev

How can I see if a relationship of a core data entity has not been set?

From Dev

Testing DataGridView to see if Cell has been Selected

From Dev

How determine if a Vaadin table row clicked in has been selected or deselected?

From Dev

How determine if a Vaadin table row clicked in has been selected or deselected?

From Dev

(Radiobutton with JSON) how to check which Radiobutton has been selected

From Dev

How can I check to see if a program has run? If it has I want to exit the program. I am working in AppleScript.

From Dev

How can I check to see if a program has run? If it has I want to exit the program. I am working in AppleScript.

From Dev

How can I add row of components to a GUI when a button has been pressed?

From Dev

How can I check if a property has been set using Swift reflection?

From Dev

How can I check if a `let` variable has been declared on ES6?

From Dev

Lotus Notes: how can i check if saved document has been modified

From Dev

How can I check if the first line of a CSV file has been written to?

From Dev

How can I check if a SKSpriteNode that has been touched also of some other type that inherits from SKSpriteNode?

From Dev

How can I check a file has been copied fully to a folder before moving it using python

From Dev

How can I check if file has been chosen to upload before submitting form

From Dev

SQL - How can I check to see if a FIELD A has all 3 specific values in FIELD B?

Related Related

  1. 1

    How can I check if jcombobox selection has not been selected?

  2. 2

    How can I see when package has been upgraded?

  3. 3

    How can I check if an appearance property has been set?

  4. 4

    How can I check if an anonymous function has been called with NSubstitute?

  5. 5

    How can I check if file has been downloaded in ansible

  6. 6

    How can I check if a bean has been loaded by springboot

  7. 7

    How can i check the radiobutton that it has been checked in this table?

  8. 8

    How can I check to see if a gif animation has completed

  9. 9

    How do I check which JNLP file that has been selected to run?

  10. 10

    How do I check if a file has been selected in a <input type="file"> element?

  11. 11

    OpenFileDialog - Check if has not been selected

  12. 12

    JqGrid check to see if the row is selected

  13. 13

    How can I see where Ubuntu has been installed on my HDD?

  14. 14

    How can I see if a relationship of a core data entity has not been set?

  15. 15

    Testing DataGridView to see if Cell has been Selected

  16. 16

    How determine if a Vaadin table row clicked in has been selected or deselected?

  17. 17

    How determine if a Vaadin table row clicked in has been selected or deselected?

  18. 18

    (Radiobutton with JSON) how to check which Radiobutton has been selected

  19. 19

    How can I check to see if a program has run? If it has I want to exit the program. I am working in AppleScript.

  20. 20

    How can I check to see if a program has run? If it has I want to exit the program. I am working in AppleScript.

  21. 21

    How can I add row of components to a GUI when a button has been pressed?

  22. 22

    How can I check if a property has been set using Swift reflection?

  23. 23

    How can I check if a `let` variable has been declared on ES6?

  24. 24

    Lotus Notes: how can i check if saved document has been modified

  25. 25

    How can I check if the first line of a CSV file has been written to?

  26. 26

    How can I check if a SKSpriteNode that has been touched also of some other type that inherits from SKSpriteNode?

  27. 27

    How can I check a file has been copied fully to a folder before moving it using python

  28. 28

    How can I check if file has been chosen to upload before submitting form

  29. 29

    SQL - How can I check to see if a FIELD A has all 3 specific values in FIELD B?

HotTag

Archive