Thursday, February 12, 2015

JTable: Bottom of text is cut / cropped when using customized table cell renderer

The same type of text looks fine in columns using the default table cell renderer, but the bottom of the text is cut in columns using a customized table cell renderer. The bottom of text is cut because the customized table cell renderer adds a border which occupies some space. All you need to do to fix it is to set the border to null.

        public class MyFieldRenderer extends DefaultTableCellRenderer {

               public Component getTableCellRendererComponent(
                       JTable table, Object value,
                       boolean isSelected,
                       boolean hasFocus,
                       int row, int col) {

                       JComponent cpnt = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, col);
                       cpnt.setBorder(null);

                       return cpnt;
               }
       }

If the text is cut all over the table, you may consider to use a smaller font or set the row height of the table to a larger value.

      Font font = table.getFont();
      table.setFont(font.getFamily(), font.getStyle(), <your size>);

      table.setRowHeight(int rowHeightInPixel);

----------------------------------------------------------------------------------------------------------------------

                        
If you have ever asked yourself these questions, this is the book for you. What is the meaning of life? Why do people suffer? What is in control of my life? Why is life the way it is? How can I stop suffering and be happy? How can I have a successful life? How can I have a life I like to have? How can I be the person I like to be? How can I be wiser and smarter? How can I have good and harmonious relations with others? Why do people meditate to achieve enlightenment? What is the true meaning of spiritual practice? Why all beings are one? Read the book free here.

No comments:

Post a Comment