• Post Reply Bookmark Topic Watch Topic
  • New Topic

Table Cell - Text  RSS feed

 
John R Roberts
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, I would like to be able to determine what text is displayed to the user in a JTable cell. So, say a cell contains the text "Hello my name is John" but the column is not wide enough to display all text so the user just sees "Hello my na...".
So I would like to get the text that is viewed by the user and not the displayable text from the underlying table model.
thanks,
 
Brian Cole
Author
Ranch Hand
Posts: 959
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by John R Roberts:
I would like to be able to determine what text is displayed to the user in a JTable cell. So, say a cell contains the text "Hello my name is John" but the column is not wide enough to display all text so the user just sees "Hello my na...".
So I would like to get the text that is viewed by the user and not the displayable text from the underlying table model.


yourTable.getValueAt(row, col)

or if you want a definite String something like
String.valueOf(yourTable.getValueAt(row, col))
 
John R Roberts
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks but this isn't exactly what I am looking to determine.
So, say my table cell is returned the following text from the underlying model -
"Hello, my name is John".
Now, my table column is not wide enough to display this String, so the text is truncated and the following is what the user can see -
"Hello, my n..."
Now, if I make my table column wider I see more text and if I make the column narrower I see less text.
So what I would like to determine is how do I know what text is being displayed to the user?
I tried to determine the width of the table cell and comparing that to the width of the String using SwingUtilities.computeStringWidth but I run into a problem where the cell is slightly wider than the text but the text is still truncated and contains '...'
So, how do I know what the real size of the cell that will be used to render the text and not the actual cell size (BTW I use the method JTable.getCellRect to get the cell width).
Hope this makes sense!!!
 
Brian Cole
Author
Ranch Hand
Posts: 959
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by John R Roberts:
thanks but this isn't exactly what I am looking to determine.
So, say my table cell is returned the following text from the underlying model -
"Hello, my name is John".
Now, my table column is not wide enough to display this String, so the text is truncated and the following is what the user can see -
"Hello, my n..."
Now, if I make my table column wider I see more text and if I make the column narrower I see less text.
So what I would like to determine is how do I know what text is being displayed to the user?


Please accept my apologies for not understanding what you were asking.

You may want to check out SwingUtilities.html.layoutCompoundLabel().

It's not documented very well, but that's where typically where the text gets truncated.

I tried to determine the width of the table cell and comparing that to the width of the String using SwingUtilities.computeStringWidth but I run into a problem where the cell is slightly wider than the text but the text is still truncated and contains '...'
So, how do I know what the real size of the cell that will be used to render the text and not the actual cell size (BTW I use the method JTable.getCellRect to get the cell width).


Did you pass false as the 3rd argument to getCellRect() ?
 
John R Roberts
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks, I'll check this out.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!