title: trouble with creating JTable to display data
body: <p>I am doing this payroll project for school.
  The idea is for the user to input the employee's name, work hour, hourly rate, and select department from the ComboBox.
  There will display 3 buttons, "Add More", "Display Result", and "exit".
  "Add More" button will store the input into several arryalist and set the textfield to blank to allow more input.
  "Display Result" will generate a JTable at the bottom JPanel to display the employee's name, department, and weekly salary.</p>
  
  <p>I am running into the problem of nothing shows up after hitting the "Display Result" button. Maybe I have misunderstand the purpose of the button event, but I am really confused right now. Please help!</p>
  
  <p>Here is a <a href="http://s443.photobucket.com/user/bigwhiteegg/media/grfha425564_zpselymr3yp.jpg.html][IMG]http://i443.photobucket.com/albums/qq159/bigwhiteegg/grfha425564_zpselymr3yp.jpg" rel="nofollow">photobucket</a> directURL PrtSc of the UI, hope it helps.</p>
  
  <pre><code>import java.awt.event.*;
  import java.awt.*;
  import javax.swing.*;
  import java.util.*;
  
  public class PayrollFrame extends JFrame
  {
      private JLabel nameMessageLabel, hourMessageLabel, rateMessageLabel, boxMessageLabel;
      private JTextField nameTextField, hourTextField, rateTextField;
      private JPanel inputPanel, buttonPanel, outputPanel, inputPanel1, inputPanel2, inputPanel3, inputPanel4;
      private JComboBox&lt;String&gt; departmentBox;
      private JButton addButton, displayButton, exitButton;
      private JTable resultTable;
      private String[] columnNames = {"Employee name", "Department", "Weekly Salary"};
      private Object[][] data;
      private int WINDOW_WIDTH = 400;
      private int WINDOW_HEIGHT = 500;
  
      ArrayList&lt;String&gt; name = new ArrayList&lt;String&gt;();
      ArrayList&lt;String&gt; hour = new ArrayList&lt;String&gt;();
      ArrayList&lt;String&gt; rate = new ArrayList&lt;String&gt;();
      ArrayList&lt;String&gt; department = new ArrayList&lt;String&gt;();
      ArrayList&lt;String&gt; salary = new ArrayList&lt;String&gt;();
  
      private String[] departments = {"IT", "Marketing", "Human Resource", "Sales", "Customer Service", "Financial"};
  
      /*default constructor*/
      public PayrollFrame()
      {
          super("Payroll");
          setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          setSize(WINDOW_WIDTH, WINDOW_HEIGHT);
          setLayout(new GridLayout(3,1));
          buildInputPanel();
          buildButtonPanel();
          buildOutputPanel();
  
          add(inputPanel);
          add(buttonPanel);
          add(outputPanel);
  
          setVisible(true);
      }
  
      private void buildInputPanel()
      {
          nameMessageLabel = new JLabel("Employee Name: ");
          hourMessageLabel = new JLabel("Work Hour: ");
          rateMessageLabel = new JLabel("Hourly Rate: ");
          boxMessageLabel = new JLabel("Department: ");
          nameTextField = new JTextField(10);
          hourTextField = new JTextField(10);
          rateTextField = new JTextField(10);
          departmentBox = new JComboBox&lt;String&gt;(departments);
  
          inputPanel = new JPanel();
          inputPanel1 = new JPanel();
          inputPanel2 = new JPanel();
          inputPanel3 = new JPanel();
          inputPanel4 = new JPanel();
  
          inputPanel1.add(nameMessageLabel);
          inputPanel1.add(nameTextField);
          inputPanel2.add(hourMessageLabel);
          inputPanel2.add(hourTextField);
          inputPanel3.add(rateMessageLabel);
          inputPanel3.add(rateTextField);
          inputPanel4.add(boxMessageLabel);
          inputPanel4.add(departmentBox);
  
          inputPanel.add(inputPanel1);
          inputPanel.add(inputPanel2);
          inputPanel.add(inputPanel3);
          inputPanel.add(inputPanel4);
      }
  
      private void buildButtonPanel() 
      {
          addButton = new JButton("Add More");
          addButton.addActionListener(new ButtonAction());
          displayButton = new JButton("Display Result");
          displayButton.addActionListener(new ButtonAction());
          exitButton = new JButton("Exit");
          exitButton.addActionListener(new ButtonAction());
  
          buttonPanel = new JPanel();
  
          buttonPanel.add(addButton);
          buttonPanel.add(displayButton);
          buttonPanel.add(exitButton);
      }
  
      private void buildOutputPanel()
      {
          outputPanel = new JPanel();
      }
  
      /*Copy ArrayList into 2D array to display in JTable format*/
      private void printData() 
      {
          for(int i=0; i&lt;name.size(); i++)
          {
              data[i][0]=name.get(i);
              data[i][2]=department.get(i);
              data[i][2]=salary.get(i);
          }
          resultTable = new JTable(data, columnNames);
          outputPanel = new JPanel();
          outputPanel.add(resultTable);
      }
  
      /*Function of 3 buttons*/
      private class ButtonAction implements ActionListener
      {
          @Override
          public void actionPerformed(ActionEvent e) 
          {
              if(e.getActionCommand()=="Add More")
              {
                  name.add(nameTextField.getText());
                  hour.add(hourTextField.getText());
                  rate.add(rateTextField.getText());
                  department.add((String) departmentBox.getSelectedItem());
                  calculateSalary(hourTextField.getText(), rateTextField.getText());
                  nameTextField.setText("");
                  hourTextField.setText("");
                  rateTextField.setText("");
              }
              else if(e.getActionCommand()=="Display Result")
              {
  
                  printData();
  
              }
              else if(e.getActionCommand()=="Exit")
              {
                  System.exit(0);
              }
          }
  
          /*Calculate the weekly salary*/
          private void calculateSalary(String hourString, String rateString) 
          {
              int tempHour = Integer.parseInt(hourString);
              double tempRate = Double.parseDouble(rateString);
              if(tempHour&lt;=40)
              {
                  salary.add(Double.toString(tempHour * tempRate));
              }
              else
              {
                  salary.add(Double.toString(40 * tempRate + (tempHour - 40) * (tempRate * 1.5))); //all hour after 40 will pay 1.5
              }
          }
      }
  }
  </code></pre>