title: JButton will not change update image when using .setIcon(ICON);
body: <p>I already checked <a href="https://stackoverflow.com/questions/17535901/why-isnt-seticon-displaying-image-on-jbutton">this</a> duplicate question and other similar ones and it didn't help. I am trying to add an png to a button when it is clicked. The program is a variable sized tic-tac-toe game for school. </p>
  
  <p>Right now I have:</p>
  
  <pre><code>private ImageIcon X_MARK = new ImageIcon("x.png");
  private ImageIcon O_MARK = new ImageIcon("o.gif");
  private JButton[][] cells;
  
  ...
  
      cells = new JButton[size][size];
      JPanel board = new JPanel(new GridLayout(size, size));
      board.setBorder(new LineBorder(Color.BLACK, 1));
  
      ButtonListener listener = new ButtonListener();
  
      for (int i = 0; i &lt; size; i++)
          for (int j = 0; j &lt; size; j++) {
              cells[i][j] = new JButton();
              cells[i][j].addActionListener(listener);
              board.add(cells[i][j]);
          }
      JFrame ttt = new JFrame();
      ttt.add(board);
      ttt.setTitle("Show GUI Components");
      ttt.setSize(60*size, 60*size);
      ttt.setLocation(0, 0);
      ttt.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      ttt.setVisible(true);
  
  ...
  
  class ButtonListener implements ActionListener {
      @Override
      public void actionPerformed(ActionEvent e) {
  
          int i, j;
  
          for (i = 0; i &lt; size; i++)
              for (j = 0; j &lt; size; j++)
                  if (e.getSource() == cells[i][j]) {
                      if ((i + j) % 2 == 0) {
                          cells[i][j].setBackground(Color.GREEN);
                          cells[i][j].setIcon(X_MARK);
                      } else {
                          cells[i][j].setBackground(Color.CYAN);
                          cells[i][j].setIcon(O_MARK);
                      }
                  }
  
      }
  }
  </code></pre>
  
  <p>That is all the relevant code I think. I am using Eclipse and I have x.png and o.png in the src folder and the bin folder of the the project. I have also tried a couple of variants I have seen on SO and google searches like, <code>new ImageIcon("C:/Users/BigBoy/workspace_1/EventDriven/src/x.png");</code>, <code>new ImageIcon("src/x.png");</code>, and some other ones involving <code>getClass().getResource</code> among other things. I don't know what else to try. I know I've done this in the past and didn't have this much trouble.</p>
  
  <p>I added <code>.setBackground(Color.GREEN);</code> just to make sure my clicks were registering properly and they are, the problem to me seems to be with the declaring/initializing of the ImageIcon.</p>
  
  <p>NOTE: Right now my button listener just makes the checker board pattern, I will get to actually putting each player's mark after I figure out this icon problem.</p>