Text coordinates in JTextPane

Greetings!

Okay, I have a JTextPane, somewhere in JTextPanes

content is a small slice of text. I know texts start

position and length. Is there some way to get x, y coordinates of

that texts start position?

And I have another question. How can I create a link between

two JScrollPanes? if I move one scroll bar down,

the other will move down as well.

Thaks, Andrey.

[422 byte] By [Andriuwkoa] at [2007-11-26 22:42:42]
# 1

> Greetings!

>

> Okay, I have a JTextPane, somewhere in JTextPanes

> content is a small slice of text. I know texts start

>

> osition and length. Is there some way to get x, y

> coordinates of

> that texts start position?

I'm confused a little bit. Do you want to find the location of the caret? Or do you already know where the text is in the String, and you want to find out what row and column it's on?

If it's the former, then look at the getCaretPosition() method of JTextComponent. If it's the latter, there should be a way to look at each line in the pane, and count characters until you get to the index of the substring in the original String. I don't know of any easier way.

> And I have another question. How can I create a link

> between

> two JScrollPanes? if I move one scroll bar down,

> the other will move down as well.

Get the JScrollPane that the JTextPane is embedded in. Get the hor. or vert. JScrollBar from the JScrollPane. Add an AdjustmentListener to recieve events when the scroll bar is scrolled. Adjust the second Scrollbar accordingly when the first is changed. Do the same for the other scrollbar.

There are some links that talk about it here:

http://www.google.com/search?q=java+scroll+listener

> Thaks, Andrey.

hunter9000a at 2007-7-10 11:58:25 > top of Java-index,Desktop,Core GUI APIs...
# 2

Thank you for your reply.

Sorry for my bad question. The position I ment is

a Java2D position(x,y). I want to put information about paragraphs

to the panel which will have exact height as JTextPane. Thats why I

need to link two JScrollPanes.

F.E. I want to get something like this:

JPanel JTextPane

Author | <author>The Smith

Text| <text> bla bla bla bla bla bla b

| bla bla bla bla bla bla bla bla

| bla bla bla bla bla bla bla bla

| bla bla bla bla bla bla bla bla

Photo| <foto>This is photo

How can I get <author>, <text> and <foto> tags "y" positions(or is it called axis?) knowing their position in the Document?

Thanks.

null

Message was edited by:

Andriuwko

Andriuwkoa at 2007-7-10 11:58:25 > top of Java-index,Desktop,Core GUI APIs...
# 3
textPane.modelToView(...);
camickra at 2007-7-10 11:58:25 > top of Java-index,Desktop,Core GUI APIs...
# 4
camickr, Thanks. I think this will solve my problem, this should do everything I need.My big mistake was that I never digged in docs of the parent classes.Thread closed.Regards, Adnrey.
Andriuwkoa at 2007-7-10 11:58:25 > top of Java-index,Desktop,Core GUI APIs...