Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Formatting a table with drawString()

 
jason adam
Chicken Farmer ()
Ranch Hand
Posts: 1932
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I understand that drawString() doesn't use text like JTextArea, but instead draws to the pixels. I've looked through FontMetrics, and probably has some methods I might be able to use, but was curious what might be the best way to show a table a of values using drawString()? I can do it easily using JTextArea, drawString() gives a whole heck of a lot more problems. I'm trying to create 3 rows, 10 columns, data left justified.
The closest thing I have is a for loop statement:

Where s is the data as a string. Basically tries to space things out evenly, but it starts to get a little messy when the data is greater than 2 characters in length.
Just a pointer in the right direction would be nice
Thanks!
Jason

[This message has been edited by jason adam (edited October 30, 2001).]
 
Tim Holloway
Saloon Keeper
Posts: 18366
56
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JTextArea is a Swing class, so I must assume that you intend to use Swing as the UI manager. Swing has a class named JTable that will handle the basic display - you can provide cell rendering class(es) if you don't like its default rendering.
That would be a lot easier than building up the whole thing yourself.
 
jason adam
Chicken Farmer ()
Ranch Hand
Posts: 1932
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, the data increments regularly through each row, and since it is a very small table, just set up a simple for loop to create it. It's only for display purposes anyway, which is why I was curious if using drawSting() would just introduce more formatting algorithms than is really warranted.
Jason
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic