This week's book giveaway is in the Java in General forum.
We're giving away four copies of Think Java: How to Think Like a Computer Scientist and have Allen B. Downey & Chris Mayfield on-line!
See this thread for details.
Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JTextPanes

 
Richard West
Ranch Hand
Posts: 127
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 1535
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 127
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic