Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.gui > #5495

Re: Identifying text truncation in JTable cells

Newsgroups comp.lang.java.gui
Date 2016-06-21 23:35 -0700
References <12e4f4ff.0305090118.65305e15@posting.google.com> <3EBB8559.4000904@yahoo.com> <12e4f4ff.0305140853.7eed19ec@posting.google.com>
Message-ID <768a123f-7a71-41b8-920d-112837b3f465@googlegroups.com> (permalink)
Subject Re: Identifying text truncation in JTable cells
From herphan@gmail.com

Show all headers | View raw


Thanks for the hints on how to do this. I elaborated a little on it trying to get rid of the TableColumn. I aldready had a subclass of DefaultTableCellRenderer doing some custom coloring in getTableCellRendererComponent(). I could extend this method for doing the tooltip stuff - see this stripped down version:

public class TableCellRendererMy extends DefaultTableCellRenderer implements TableCellRenderer {

  public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
      super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
      
      double cellPrefWidth = getPreferredSize().getWidth();
      double cellWidth= table.getCellRect(row, column, false).getWidth();
      
      if (cellPrefWidth>cellWidth) {
        try {
            setToolTipText(String.valueOf(value));
        } catch (Exception e) {
        }
      }
      
      return this;
  }
}

regerds,
stephan

Back to comp.lang.java.gui | Previous | Next | Find similar


Thread

Re: Identifying text truncation in JTable cells herphan@gmail.com - 2016-06-21 23:35 -0700

csiph-web