• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JTextArea & Cursor

 
Ranch Hand
Posts: 384
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Davy Kelly
Ranch Hand
Posts: 384
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks marc,

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

davy
 
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 384
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't follow...


will have both lines/words at the right.

can you post an example of the problem?
 
Davy Kelly
Ranch Hand
Posts: 384
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
here is the program, and I put text on the first JTextArea

davy
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I meant code example, like this

 
Davy Kelly
Ranch Hand
Posts: 384
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
works OK for me, java 1.5.0_05
 
Davy Kelly
Ranch Hand
Posts: 384
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 384
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
setMargin() works for all rows.

perhaps the current problem is the 'space' you're adding to the first row (?)
 
Davy Kelly
Ranch Hand
Posts: 384
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
> 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
Posts: 384
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


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
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 384
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you very much michael,

you have been extremely helpful.
I am grateful.

it worked wonderfully.

davy
 
reply
    Bookmark Topic Watch Topic
  • New Topic