• Post Reply Bookmark Topic Watch Topic
  • New Topic

how to get the display size(width) of a String object?  RSS feed

 
Mahmoud Hadad
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi evreyone,
don't know i've been looking over for how to get the display size(width) of a String object for a quite time and could not get a usefull answear .anyway i want to know how i can get the display size(width) on screen for a specified String object.i tried length() but it returned number of char unites inside the String object not it's display size(width) ,so does anyone knows about this ?
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24215
37
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use the java.awt.FontMetrics class.
 
Mahmoud Hadad
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i have the number of characters that i got from making a comparison between some String objects on which one of them have the biggest characters but i do not have the original String .what i want to do originally is to resize my JTable columns automatically to fit to my field's text automatically ,so how this is done in java ?i think i tried to keep my approach simple but things got complicated by time.
thanks for the reply.
 
shansi raj
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If I had interpreted your question correctly, then try using table.setAutoResizeMode().
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!