Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You'd have to be able to know the number of lines &amp; the text height used by the jtable. From there you can set the row height (globally for the table, or for individual rows).</p> <p>You would then need a table cell renderer capable of displaying multi line content.</p> <p>Depending on your requirements, you'd might be better of displaying a one line summary of the cell &amp; allow for tooltips to display the full content (depending on the size of te content) or a popup window with a none editable text component</p> <p><strong>UPDATE</strong></p> <p>Sorry for the short comment, I was on my IPad.</p> <p>You have two choices, depending on what state your UI is in. You can grab a reference to the FontMatrics from the JTables graphics context. This will only work if the JTable has been realised (rendered on the screen)</p> <pre><code>FontMetrics fm = myTable.getFontMetrcis(myTable.getFont()); int height = fm.getHeight(); </code></pre> <p>This example, of course, assumes you are using the same font as the JTable. If not, you'll need to supply the correct font.</p> <p>Or, if the UI hasn't been realised yet, you'll need to construct a compatible image a extract the font metrics from it. This is a little more complicated as it begins to deal with the graphics configuration and devices...</p> <pre><code>BufferedImage img = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration().createCompatibleImage(1, 1, Transparency.TRANSLUCENT); Graphics2D g2d = img.createGraphics(); FontMetrics fm = g2d.getFontMetrics(font); int height = fm.getHeight(); g2d.dispose(); </code></pre> <p>Once you have the height of the font, you should be able to calculate the height of the text, assuming the text is broken up into lines (or you can split the lines your self). Now if that's not the case (or you want to provide you own word/line wrapping), this become increasingly complicated.</p> <p>You can check here <a href="http://docs.oracle.com/javase/tutorial/2d/text/drawmulstring.html" rel="nofollow">http://docs.oracle.com/javase/tutorial/2d/text/drawmulstring.html</a> for how to render text using graphics2D for hints (you can use this to split text into groups as you need)</p> <p>You might also want to check out <a href="http://www.jroller.com/santhosh/entry/multiline_in_table_cell_editing1" rel="nofollow">http://www.jroller.com/santhosh/entry/multiline_in_table_cell_editing1</a> which shows a great idea for a multi line editor.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload