aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes JTextPanes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JTextPanes" Watch "JTextPanes" New topic
Author

JTextPanes

Richard West
Ranch Hand

Joined: Jan 07, 2005
Posts: 127
Hi everyone,

Let's say that i have some embedded JComponents in a JTextPane, how do i find out the starting caret position of where the JComponents are currently embedded at?

Any help is greatly appreciated

Yours Sincerely

Richard West
Craig Wood
Ranch Hand

Joined: Jan 14, 2004
Posts: 1535
Have a look at the TextSamplerDemo.java referenced/discussed on the How to Use Editor Panes and Text Panes page. In the addStylesToDocument method, at the bottom, a JButton is added to a Style in the StyledDocument with a static StyleConstants method. Thinking about reversing this to get a reference to a component you might get the StyledDocument, get the Styles, traverse them, get the attribute names for each Style (look for StyleConstant with ComponentAttribute) and use them to look up the attribute values (look for a Component (instanceof JComponent)). DefaultStyledDocument has a getStyleNames method that looks handy.
Richard West
Ranch Hand

Joined: Jan 07, 2005
Posts: 127
Hi everyone,

My problem stems from mainly in the ComponentView of the main JTextPane, the links you showed me does not seem to have anything about ComponentViews.

Richard West
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JTextPanes