• Post Reply Bookmark Topic Watch Topic
  • New Topic

Aligning text in a JTextArea  RSS feed

 
John Brookes
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I need to put two strings onto one line, with the first string left-aligned and the second right-aligned (repeated for a few lines), but I can't find any useful alignment methods for the JTextArea class. The API shows final variables for RIGHT_ALIGNMENT, etc, and methods for setAlignmentY but either I can't use them properly or they're not working. I've imported javax.swing.* and java.awt.* - am I missing something?

Example:
JTextArea
|-----------------------|
|String 1.......String 2|
|String 3.......String 4|
|.......................|
|.......................|
|.......................|
|.......................|
|-----------------------|
[Edit #2: Can't draw this example right at all, hope you get the idea anyway]
Cheers,
JB
[ March 17, 2004: Message edited by: John Brookes ]
[ March 17, 2004: Message edited by: John Brookes ]
 
Stefan Wagner
Ranch Hand
Posts: 1923
Linux Postgres Database Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I guess this isn't possible in a normal way (and a gui-question, but I'm not able to move this thread around).
Even in OpenOffice:Writer, KWriter or Word, you may not assign two alignments for one paragraph, and paragraphs are seperated by CR/LF, CR or LF.
In a textprocessing app you may help yourself with a table inserted, and two columns, and then align the columns.
So a similar trick - table, or fields with 0-border, could give you the wanted expression.
 
John Brookes
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yeah I split it into two separate JTextAreas side by side. It looks like one box but the corresponding strings can be added into either so it looks like columns. The thing is, you still can't right-align the strings in the right-hand area
Well, I can't anyway
I've searched the site and there's nothing about this. Must be a pretty evil problem.
Thanks for the help anyway
 
Nigel Browne
Ranch Hand
Posts: 704
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
John,
I would have a look at using JTextPane instead. Here is an example of adding a right aligned style to one.

hth
Nigel
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!