1

lines like this:

 id    title         price    quantity    sum

 001   c++ primer    20.0     5           100.0

I want the two lines look like the above .The first line is the head.

And lines below are information about books. I try to use blanks to achice it,

but it's not that good.can you help?thank you.

2
  • See this question: stackoverflow.com/questions/4338521/…
    – dacwe
    Commented Jan 1, 2011 at 11:24
  • sure you do not want to use a table? You may add such features as editing or copying to this component, too.
    – mtraut
    Commented Jan 1, 2011 at 12:24

4 Answers 4

2

Use a Formatter object.

0
1

The better choice is to use a JTable. Read the section from the Swing tutorial on How to Use Tables for more information and working examples.

If you must use a JTextArea, then you need to use a monospaced font.

textArea.setFont( new Font("monospaced", Font.PLAIN, 10) );

or any other font that that has a fixed size for each character.

0

Of course, you have to use a fixed-width-font. But detecting one which works for all characters is not trivial (or impossible?), because, e.g., Asian characters usually are two latin characters wide.

0

I would use a JEditorPane here with "text/html" content type and make an HTML table.

Not the answer you're looking for? Browse other questions tagged or ask your own question.