Forums Register Login

JTextArea & Cursor

+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
thanks marc,

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

davy
+Pie Number of slices to send: Send
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)
+Pie Number of slices to send: Send
ok, My JTextAreas have 2 lines,

How can I make both lines start like that?

davy
[ March 07, 2007: Message edited by: Davy Kelly ]
+Pie Number of slices to send: Send
I don't follow...


will have both lines/words at the right.

can you post an example of the problem?
+Pie Number of slices to send: Send
here is the program, and I put text on the first JTextArea

davy
+Pie Number of slices to send: Send
I meant code example, like this

+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
works OK for me, java 1.5.0_05
+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
setMargin() works for all rows.

perhaps the current problem is the 'space' you're adding to the first row (?)
+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
> I got rid of that " " but the set margin is not working....

what changes did you make to your previously posted code?
+Pie Number of slices to send: Send


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
+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
Thank you very much michael,

you have been extremely helpful.
I am grateful.

it worked wonderfully.

davy
Stinging nettles are edible. But I really want to see you try to eat this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 5184 times.
Similar Threads
JTextArea question
Cursor handling in JTextArea
Issues with JTextArea as cellEditor of JTable Column.
Tab doesn't work in applet
Make line break (go to new line) while writing text on JPanel
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 04:30:01.