java - How to get JTextPane to display ellipsis to signal text overflow? -



java - How to get JTextPane to display ellipsis to signal text overflow? -

i using jtextpane table cell renderer display rich text. when text long fit within cell, truncated. mimic jlabel behavior, i.e. show ellipsis (...) alert user part of text not visible. has done before?

solution ended adopting, help stanislavl. algorithm works chopping off 1 character @ time off end of styleddocument, appending "..." , comparing resulting preferred width table cell width. inefficient, in case of long strings, not problem in case. can optimized. next goes renderer's gettablecellrenderercomponent

m_dummytextpane.setdocument(doc); m_dummytextpane.setsize(short.max_value, table.getrowheight()); int width = m_dummytextpane.getpreferredsize().width; int start = doc.getlength() - 1; while(width >= table.getcolumnmodel().getcolumn(col).getwidth() && start>0) { seek { doc.remove(math.min(start, doc.getlength()), doc.getlength() - math.min(start, doc.getlength())); doc.insertstring(start, "...", null); } grab (badlocationexception e) { e.printstacktrace(); break; } start--; width = m_dummytextpane.getpreferredsize().width; }

you can utilize http://java-sl.com/tip_text_height_measuring.html measure content fixed width. if requires more space available paint on jtextpane.

i trashgod's thought scroll too. (+1)

java swing jtable jtextpane renderer

Comments

Popular posts from this blog

iphone - Dismissing a UIAlertView -

intellij idea - Update external libraries with intelij and java -

javascript - send data from a new window to previous window in php -