title: JTable in JScrollPane
body: <p>I am adding <code>JTable</code> in a <code>JScrollPane</code> then adding scrollpane to the panel, then adding panel to the frame but it doesn't work here's the code. I want to have scroll bar on table or frame that will make table scrollable so user can see it. I have tried many ways but non worked for me
    here is the whole code</p>
  
  <pre><code>public class View extends JFrame {
  
  private static final long serialVersionUID = 1L;
  
  /**
   * Launch the application.
   */
  //here in the main method i it adds in the JFrame everything
  
  public static void main(String[] args) {
      EventQueue.invokeLater(new Runnable() {
          public void run() {
              try {
                  View frame = new View();
                  frame.setVisible(true);
              } catch (Exception e) {
                  e.printStackTrace();
              }
          }
      });
  }
  
  public void showData() throws SQLException, ParseException {
  
      panel = new JPanel();
      panel_1 = new JPanel();
      model_1 = new DefaultTableModel();
      model_2 = new DefaultTableModel();
  
      model_1.addColumn("Title");
      model_1.addColumn("Priority ");
      model_1.addColumn("DeadLine");
      model_1.addColumn("Time");
      model_1.addColumn("Progress");
  
      model_2.addColumn("Task Title");
      model_2.addColumn("Priority ");
      model_2.addColumn("DeadLine");
      model_2.addColumn("Time");
      model_2.addColumn("Done");
  
      Database obj = new Database();
  
      ArrayList&lt;Task&gt; list = obj.getTasks();
      for (int i = 0; i &lt; list.size(); i++) {
  
          Task task = list.get(i);
          Object[] row = { task.title, task.priority, task.deadine,
                  task.time, task.progress };
  
          // Comparing Dates
  
          Calendar currentDate = Calendar.getInstance();
          SimpleDateFormat formatter = new SimpleDateFormat("MM-d-yyyy");
          String dateNow = formatter.format(currentDate.getTime());
  
          java.util.Date systemDate = new SimpleDateFormat("MM-d-yyyy",
                  Locale.ENGLISH).parse(dateNow);
  
          if (!task.deadine.before(systemDate)) {
              // add row to to do tab
              model_1.addRow(row);
          } else {
              // add row to done tab
              model_2.addRow(row);
          }
  
          // **********************
  
      }
  
      toDoTable = new JTable(model_1);
      doneTable = new JTable(model_2);
      toDoTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
      doneTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
      toDoTable.setFillsViewportHeight(true);
      doneTable.setFillsViewportHeight(true);
  
  //here i add the JScrollPane  and it doesnt work 
  
      JScrollPane jpane = new JScrollPane(toDoTable);
      JScrollPane jpane1 = new JScrollPane(doneTable);
  
      panel.add(jpane);
      panel_1.add(jpane1);
      panel.add(jpane);
      panel_1.add(jpane1);
  
  }
  }    
  </code></pre>