title: JTable: How to update cell using custom editor by pop-up input dialog box?
body: <p>I am learning from this <a href="http://docs.oracle.com/javase/tutorial/uiswing/components/table.html#renderer" rel="nofollow">oracle tutorial</a> that uses <a href="http://docs.oracle.com/javase/tutorial/uiswing/examples/components/index.html#TableDialogEditDemo" rel="nofollow">TableDialogEditDemo.java</a> example class</p>
  
  <p>I wrote a custom cell Renderer and Editor for JTable.</p>
  
  <p>I register them to this Oracle <a href="http://docs.oracle.com/javase/tutorial/uiswing/examples/components/TableDialogEditDemoProject/src/components/TableDialogEditDemo.java" rel="nofollow">TableDialogEditDemo.java</a> class</p>
  
  <pre><code>        ...
          ...
          //Set up renderer and editor for the Favorite Color column.
          table.setDefaultRenderer(Color.class,
                                   new ColorRenderer(true));
          table.setDefaultEditor(Color.class,
                                 new ColorEditor());
  
          TableColumn c = table.getColumnModel().getColumn(2);
          c.setCellRenderer(new CellStringRenderer()); //My custom Renderer
          c.setCellEditor(new CellStringEditor()); // My custom Editor
  
          //Add the scroll pane to this panel.
          add(scrollPane);
          ...
          ...
  </code></pre>
  
  <p>(<strong>Updated description</strong>)
  When I click on a cell an input dialogue box pops up and that is OK, and when I type a text and click "OK" the cell in the JTable is updated, but text is not displayed/rendered correctly, I have to click on any other cell to make the text content displayed correctly in the cell. </p>
  
  <p>What is the wrong with my code?.</p>
  
  <p>My Renderer</p>
  
  <pre><code>import java.awt.Component;
  import javax.swing.JLabel;
  import javax.swing.JTable;
  import javax.swing.table.TableCellRenderer;
  
  public class CellStringRenderer extends JLabel implements TableCellRenderer
  {
  
      public CellStringRenderer()
      {
          this.setOpaque(true);
      }
  
  
      @Override
      public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column)
      {
         String stringValue = (String) value;
         this.setText(stringValue);
         return this;
      }
  
  }
  </code></pre>
  
  <p>My Editor (<strong>Updated</strong>)</p>
  
  <pre><code>import java.awt.Component;
  import javax.swing.*;
  import javax.swing.table.TableCellEditor;
  
  
  public class CellStringEditor extends AbstractCellEditor
          implements TableCellEditor
  {
  
      String input;
  
      @Override
      public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column)
      {
          if (isSelected)
          {
              JOptionPane dialog = new JOptionPane();
              input = dialog.showInputDialog(null, "new value");
              return dialog;   
          }
          return null;
      }
  
      @Override
      public Object getCellEditorValue()
      {
          return input;
      }
  }
  </code></pre>