• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

Formatting a table with drawString()

 
Chicken Farmer ()
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).]
 
Saloon Keeper
Posts: 22109
151
Android Eclipse IDE Tomcat Server Redhat Java 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 ()
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
 
The City calls upon her steadfast protectors. Now for a tiny ad:
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic