This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Swing / AWT / SWT and the fly likes JTextArea & Cursor Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JTextArea & Cursor" Watch "JTextArea & Cursor" New topic
Author

JTextArea & Cursor

Davy Kelly
Ranch Hand

Joined: Jan 12, 2004
Posts: 384
Hey everyone,

I would like to have some JTextAreas have the cursor sit out to the right of the edge of that area, for all rows of the JTextArea.

is this possible?

if so what should I be looking for in the API?

davy


How simple does it have to be???
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

Center and right justification in JTextAreas was requested in Bug 4201966. The evaluation states, "You can do it via Document in case document is instanceof StyledDocument."

I'm not familiar with these interfaces (Document and StyledDocument), but that's where I would start looking.


"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
Davy Kelly
Ranch Hand

Joined: Jan 12, 2004
Posts: 384
thanks marc,

I am not familiar with these either...oh well I think this will need to wait a while

davy
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
do you want the typed text to appear from the right?

if so, this may do what you want
textArea.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);

for the cursor to initially appear on the right (when program opens), add
these 2 lines prior to setting the frame's visibility to true

(this is needed in java 1.4.0_01)
Davy Kelly
Ranch Hand

Joined: Jan 12, 2004
Posts: 384
ok, My JTextAreas have 2 lines,

How can I make both lines start like that?

davy
[ March 07, 2007: Message edited by: Davy Kelly ]
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
I don't follow...


will have both lines/words at the right.

can you post an example of the problem?
Davy Kelly
Ranch Hand

Joined: Jan 12, 2004
Posts: 384
here is the program, and I put text on the first JTextArea

davy
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
I meant code example, like this

Davy Kelly
Ranch Hand

Joined: Jan 12, 2004
Posts: 384
here is the Booking Sheet in its entirety, without the date picker ok, the code could be cleaner, remember this is my very first program, that I am building from scratch.


davy
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
works OK for me, java 1.5.0_05
Davy Kelly
Ranch Hand

Joined: Jan 12, 2004
Posts: 384
I know it works,

problem is in JTextArea for say 9:00 am, the first line starts one space in, but line two of 9:00am does not...

davy
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
all through this it seemed you wanted your text right-justified.
now it seems you just want the text indented a bit.

if so, add this line
textArea.setMargin(new Insets(0,5,0,0));//5 from left, modify to suit
Davy Kelly
Ranch Hand

Joined: Jan 12, 2004
Posts: 384
thanks,

well I am sorry if it seems as if I wanted right justification, but thats not really what I want.

I like the insets idea, but if you have a look at the image above in this thread, it has one text area, that text areas have 2 rows, those 2 rows do not get the same inset, it only deals with the first row.

I think I am either going to have to leave this as is, or try and figure out DOcument...

but thanks anyway

davy
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
setMargin() works for all rows.

perhaps the current problem is the 'space' you're adding to the first row (?)
Davy Kelly
Ranch Hand

Joined: Jan 12, 2004
Posts: 384
I got rid of that " " but the set margin is not working....

it compiles fine, but just not working.

I have tried the API, changed the ints for setMargin

davy
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
> I got rid of that " " but the set margin is not working....

what changes did you make to your previously posted code?
Davy Kelly
Ranch Hand

Joined: Jan 12, 2004
Posts: 384


I commented out the setText() and added the line you gave me, and played with the values,

checked the API, said something about the borders insets.... not sure, need to check the border class now

davy
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
well, I learned something out of this - setMargin doesn't work when a border is set
(not in 1.4.0_01, anyway)

there seems to be a workaround:

comment out the 3 lines where you set the border
1) at the beginning of the for()
2) in the if(x == 3)
3) in the if(x == 9)

then, at the bottom of the for(), where you add appointmentArray[x] to sheetBox



basically, puts the border around a panel, instead of the textArea
Davy Kelly
Ranch Hand

Joined: Jan 12, 2004
Posts: 384
Thank you very much michael,

you have been extremely helpful.
I am grateful.

it worked wonderfully.

davy
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JTextArea & Cursor