title: Table cells with HTML strings inconsistently rendered as multiline
body: <p>Cells of one of columns in my table are HTML strings. HTML is used to provide some color indication. Usually the width of the column is enough to contain the whole string. But when it is not enough then the string is nicely cut on a word boundary. This is the desired behavior. The default cell renderer is used.</p>
  
  <p>I noticed that occasionally, some interaction with the table triggers the rendererer to wrap the string. As I understand, wrapping the HTML string is a normal behavior of <code>JLabel</code> from which <code>DefaultTableCellRenderer</code> derives. What is not clear is why is this behavior so inconsistent and what triggers its deviation. What is the reason for <code>JLabel</code> to jump back and forth, as if its being constantly re-measured? See attached image for an example. </p>
  
  <p>To solve the problem I can either add <code>&lt;nobr&gt;</code> to the HTML string to prevent wrapping, or use a more sophisticated renderer to render colored strings. But I wonder if there is a way to make <code>JLabel</code> play nice. </p>
  
  <p>I managed to reduce the whole case to a simple example. What I do to reproduce the issue is click various rows to change selection. </p>
  
  <p><img src="https://i.stack.imgur.com/NrGEn.gif" alt="enter image description here"></p>
  
  <pre><code>import java.awt.BorderLayout;
  import java.awt.Dimension;
  import java.util.Locale;
  
  import javax.swing.JFrame;
  import javax.swing.JLabel;
  import javax.swing.JPanel;
  import javax.swing.JScrollPane;
  import javax.swing.JTable;
  import javax.swing.SwingUtilities;
  import javax.swing.table.DefaultTableModel;
  
  public class TestTable extends JPanel{
      public TestTable() {
          setLayout(new BorderLayout());
  
          Object[][] rows = { 
                  { "&lt;html&gt;&lt;font color=red&gt;1 Lorem ipsum&lt;/font&gt; dolor sit amet, " +
                          "consectetur adipiscing elit. In lectus dolor&lt;/html&gt;"},
                  { "&lt;html&gt;&lt;font color=green&gt;2 Lorem ipsum&lt;/font&gt; dolor sit amet, " +
                          "consectetur adipiscing elit. In lectus dolor&lt;/html&gt;"},
                  { "&lt;html&gt;&lt;font color=blue&gt;3 Lorem ipsum&lt;/font&gt; dolor sit amet, " +
                          "consectetur adipiscing elit. In lectus dolor&lt;/html&gt;"},
                  { "&lt;html&gt;&lt;font color=red&gt;4 Lorem ipsum&lt;/font&gt; dolor sit amet, " +
                          "consectetur adipiscing elit. In lectus dolor&lt;/html&gt;"},
                  { "&lt;html&gt;&lt;font color=green&gt;5 Lorem ipsum&lt;/font&gt; dolor sit amet, " +
                          "consectetur adipiscing elit. In lectus dolor&lt;/html&gt;"},
  
                  };
          Object[] columns = {"Column"};
  
          DefaultTableModel model = new DefaultTableModel(rows, columns) {
              @Override
              public boolean isCellEditable(int row, int column) {
                  return false;
              }
          };
          JTable table = new JTable(model);
          table.setRowHeight(table.getFont().getSize() * 2);
  
          add(new JScrollPane(table));
  
          add(new JLabel(String.format("%s, %s, JRE %s (%s)", 
                  System.getProperty("os.name"), System.getProperty("os.arch"), 
                  System.getProperty("java.version"), Locale.getDefault().toString())), 
                  BorderLayout.SOUTH);
      }
  
      public Dimension getPreferredSize() {
          return new Dimension(300, 200);
      }
  
      public static void main(String[] args) {
          SwingUtilities.invokeLater(new Runnable() {   
              public void run() {   
                  JFrame frame = new JFrame("Test");
                  frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                  frame.setLocationByPlatform(true);
  
                  TestTable panel = new TestTable();
                  frame.add(panel);
                  frame.pack();
  
                  frame.setVisible(true);
              }
          });
      }
  }
  </code></pre>
  
  <p>My environment is Java 7 Win 7 x64, also tested with Java 6 and 8 and it looks the same. </p>