title: How to Add Table header and Scrollbar in jtable. java
body: <p>I am trying to add a Table <strong>header</strong> and <strong>Scrollbar</strong> in <code>JTABLE</code>, but I'm not getting what I want. I have tried with 3 different procedures, but did not come up with the right one. This code is for <strong>Scrollbar</strong>.</p>
  
  <p>Can any one tell me how to add header. I can't add it just as <code>model.addRow()</code> because after that I have to get the values from the table and this method create problems with that. and How to add Scroll bar code too.</p>
  
  <p>This is my Code </p>
  
  <pre><code>DefaultTableModel model = new DefaultTableModel();      
  JTable table = new JTable(model);
  table.setFont(new Font("Times New Roman", Font.PLAIN, 13));
  //JScrollPane scrollPane = new JScrollPane(table);   //Try one
  //new JScrollPane(table, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED ); // Try 2
  
  
  model.addColumn("ID");
  model.addColumn("NAME");
  model.addColumn("MODEL");
  model.addColumn("P_Price");
  model.addColumn("S_Price");
  model.addColumn("Quantity");
  
  table.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);    
  table.setBounds(10, 0, 457, 103);
  
  //panel_1.add(new JScrollPane(table)); Try 3
  //panel_1.add(scrollPane); //link to Try one
  //table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); // link 2 Try 2
  
  panel_1.add(table);
  </code></pre>