Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.help > #2533
| From | Knute Johnson <nospam@rabbitbrush.frazmtn.com> |
|---|---|
| Newsgroups | comp.lang.java.help |
| Subject | Re: JTextPane.modelToView() exception |
| Date | 2013-02-22 15:33 -0800 |
| Organization | A noiseless patient Spider |
| Message-ID | <kg8v6a$e38$1@dont-email.me> (permalink) |
| References | <d04155b6-9b24-42d5-9f82-d24fae55982b@googlegroups.com> |
On 2/22/2013 13:52, Fred Kleinschmidt wrote:
> I am getting a BadLocationException from a call to textpane.modelToView()
> when the position I pass should be legal.
>
> I create a JTextPane and get its document:
> JTextPane jtp = new JTextPane();
> Document doc = jtp.getDocument();
> Then I add a document listener to the document.
>
> This is inside a DocumentListener's insertUpdate() method:
> public void insertUpdate( DocumentEvent event ) {
> Document doc = event.getDocument();
> int len = doc.getLength();
> if ( len > 0 ) {
> try {
> Rectangle view = jtp.modelToView(len-1);
> // do other things here
> } catch (Exception e) {
> e.printStackTrace();
> }
> }
> }
>
> Everything is fine until I enter the first character after a newline.
> Then I get a BadLocationException: Position not represented by view
> (I am using Java 1.6, on a Windows 7 platform)
>
An SSCCE would have been really nice here. But I think the behavior you
are seeing is normal. I'm curious as to what you are really trying to
do with the result of the JTextComponent.modelToView() call? Best I can
tell the purpose of that method is to facilitate cursors.
knute...
Back to comp.lang.java.help | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
JTextPane.modelToView() exception Fred Kleinschmidt <fred.l.kleinschmidt@gmail.com> - 2013-02-22 13:52 -0800
Re: JTextPane.modelToView() exception Knute Johnson <nospam@rabbitbrush.frazmtn.com> - 2013-02-22 15:33 -0800
Re: JTextPane.modelToView() exception Fred Kleinschmidt <fred.l.kleinschmidt@gmail.com> - 2013-02-25 07:48 -0800
Re: JTextPane.modelToView() exception Knute Johnson <nospam@knutejohnson.com> - 2013-02-25 09:08 -0800
csiph-web