title: Java: Select JTable row, retrieve value, click button that uses value
body: <p>I have this JTable which shows "Jobs" and a button "Apply" that would be clicked after single clicking this row of Job in this JTable. I need this button to retrieve this row value and then bring users to another panel which will use this value. I have an error in my Apply button "jobid cannot be resolved", how do I retrieve the jobid that was selected from the JTable and be used on the button?</p>
  
  <p>My JTable code:</p>
  
  <pre><code>    JScrollPane scrollPane = new JScrollPane();
      scrollPane.setBounds(184, 198, 628, 338);
      add(scrollPane);
      setLayer(scrollPane, 3);
      table = new JTable();
      scrollPane.setColumnHeaderView(table);
      setTableModelFromDB();
      setLayer(table, 3);
      scrollPane.setViewportView(table);
      scrollPane.setColumnHeaderView(table.getTableHeader());
  </code></pre>
  
  <p>JTable's MouseAdapter:</p>
  
  <pre><code>            table.addMouseListener(new MouseAdapter() {
              public void mouseClicked(MouseEvent ex) {
              if (ex.getClickCount() == 2) {
               int rowSelected = table.getSelectedRow();
               if(rowSelected &gt;= 0){
                int jobid = (Integer) table.getModel().getValueAt(rowSelected, 0);
                Job j1 = Job.retrieveJobById(jobid);
                JLayeredPane contentPane = new JobPanel(mf, j1);
                mf.setContentPane(contentPane);
                mf.setVisible(true);
  
              }
             }
              else if (ex.getClickCount() == 1) {
                   int rowSelected = table.getSelectedRow();
                   if(rowSelected &gt;= 0){
                       int jobid = (Integer) table.getModel().getValueAt(rowSelected, 0);
                      }
              }
            }
  
           });
  </code></pre>
  
  <p>Apply Button:</p>
  
  <pre><code>        JButton ApplyJob = new JButton("Apply");
      ApplyJob.addActionListener(new ActionListener() {
  
          public void actionPerformed(ActionEvent arg0) {
              // check for selected row first
              if (table.getSelectedRow() != -1) {
                  // remove selected row from the model
                  JLayeredPane contentPane = new ApplyJobPanel(mf, jobid);
                  mf.setContentPane(contentPane);
                  mf.setVisible(true);     
                 }
          }
      });
      ApplyJob.setFont(new Font("Segoe UI", Font.PLAIN, 16));
      ApplyJob.setBounds(233, 559, 137, 50);
      setLayer(ApplyJob, 3);
      add(ApplyJob);
  </code></pre>