title: Truncated JTable print output
body: <p>I have a JTable that uses JTextArea as its TableCellRenderer, so that table cells can utilize word wrap.  The JTable displays fine.  When I print the table to a printer via JTable's <a href="http://download.oracle.com/javase/6/docs/api/javax/swing/JComponent.html#print%28java.awt.Graphics%29" rel="nofollow">print method</a>, the output is always truncated at approximately 60% of the data.  I have tried different computers and different printers, and different printer drivers, different JVM versions (1.5, 1.6) but none of that has helped.  Below is a self-contained Java main class that reproduces the problem.  Any ideas?</p>
  
  <pre><code>import java.awt.*;
  import java.awt.event.*;
  import java.awt.print.*;
  import java.util.*;
  import javax.swing.*;
  import javax.swing.table.*;
  
  public class JTextAreaJTableTest extends javax.swing.JFrame {
  
      public static void main(String args[]) {
          java.awt.EventQueue.invokeLater(new Runnable() {
              public void run() {
                  JTextAreaJTableTest frame = new JTextAreaJTableTest();
                  frame.setSize(640, 480);
                  frame.setLocationRelativeTo(null);
                  frame.setVisible(true);
              }
          });
      }
  
      JButton jButtonPrint;
      JScrollPane jScrollPane;
      JTable jTable;
      JToolBar jToolBar;
  
      public JTextAreaJTableTest() {
          initComponents();
  
          DefaultTableModel dtm = (DefaultTableModel) jTable.getModel();
          Vector&lt;Vector&lt;String&gt;&gt; data = new Vector&lt;Vector&lt;String&gt;&gt;();
          for (int i = 0; i &lt; 50; i++) {
              Vector&lt;String&gt; rowData = new Vector&lt;String&gt;();
              rowData.add("Entry " + i);
              rowData.add("Lorem ipsum dolor sit amet, consectetur adipisicing"
                      + " elit, sed do eiusmod tempor incididunt ut labore et"
                      + " dolore magna aliqua. Ut enim ad minim veniam, quis"
                      + " nostrud exercitation ullamco laboris nisi ut aliquip"
                      + " ex ea commodo consequat. Duis aute irure dolor in"
                      + " reprehenderit in voluptate velit esse cillum dolore"
                      + " eu fugiat nulla pariatur. Excepteur sint occaecat"
                      + " cupidatat non proident, sunt in culpa qui officia"
                      + " deserunt mollit anim id est laborum. " + i);
              data.add(rowData);
          }
          Vector&lt;String&gt; columnNames = new Vector&lt;String&gt;();
          columnNames.add("Key");
          columnNames.add("Value");
          dtm.setDataVector(data, columnNames);
          jTable.setDefaultRenderer(String.class, null);
          jTable.getColumnModel().getColumn(0).setCellRenderer(
                  new TextAreaCellRenderer());
          jTable.getColumnModel().getColumn(1).setCellRenderer(
                  new TextAreaCellRenderer());
      }
  
      private void initComponents() {
          jToolBar = new JToolBar();
          jButtonPrint = new JButton();
          jScrollPane = new JScrollPane();
          jTable = new JTable();
  
          setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
  
          jToolBar.setRollover(true);
  
          jButtonPrint.setText("Print");
          jButtonPrint.setFocusable(false);
          jButtonPrint.setHorizontalTextPosition(SwingConstants.CENTER);
          jButtonPrint.setVerticalTextPosition(SwingConstants.BOTTOM);
          jButtonPrint.addActionListener(new ActionListener() {
              public void actionPerformed(ActionEvent evt) {
                  jButtonPrintActionPerformed(evt);
              }
          });
          jToolBar.add(jButtonPrint);
  
          getContentPane().add(jToolBar, BorderLayout.NORTH);
  
          jScrollPane.setViewportView(jTable);
  
          getContentPane().add(jScrollPane, BorderLayout.CENTER);
      }
  
      private void jButtonPrintActionPerformed(ActionEvent evt)                                             
      {                                                 
          try {
              jTable.print();
          } catch (PrinterException ex) {
              ex.printStackTrace();
          }
      }                                            
  
      public static class TextAreaCellRenderer extends JTextArea implements
              TableCellRenderer {
  
          public TextAreaCellRenderer() {
              this.setLineWrap(true);
              this.setWrapStyleWord(true);
          }
  
          public Component getTableCellRendererComponent(JTable table, 
                  Object value, boolean isSelected, boolean hasFocus,
                  int row, int column) {
              this.setText(String.valueOf(value));
              TableColumnModel columnModel = table.getColumnModel();
              this.setSize(columnModel.getColumn(column).getWidth(), 1);
              int newHeight = this.getPreferredSize().height;
              if (newHeight &gt; table.getRowHeight(row)) {
                  table.setRowHeight(row, this.getPreferredSize().height);
              }
              return this;
          }
      }
  }
  </code></pre>