Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

ModelToView in JTextPane  RSS feed

 
Paulo Faria
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm trying to use this code to find the index of the last visible char in a JTextPane, origin and terminus being Points:

protected int getLastVisibleOffset(){
origin.setLocation(getLocation());
terminus.setLocation(origin.x+getWidth(),origin.y+getHeight());
System.out.println("terminus : "+getUI().viewToModel(this,terminus));
return getUI().viewToModel(this,terminus);
}

Only it doen't return the right index. Instead it get the size of the string inserted into the document, if the jTextPane is visible, or (expected -1) if it is not.

Anyone knows whats up with that?
[ February 13, 2006: Message edited by: Paulo Faria ]
 
Paulo Faria
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Obviously i was talking about viewtomodel.

Well i did some tests, and it seems that the componet getHeigth/getWidth
or getX/getY are a little flaky.

Tests:

This is a normal mouse listener that displays where in the underlying model the text that you clicked is. It works(tm)



This is just a resize listener that i made just for testing why the viewtomodel method gives the whole document length when i try to do the same thing automatically.
This also works(on linux, didn't test it in windows yet) but notice the -3 there. If that wasn't there the returned value would be the document length.

I am unhappy about this. It looks like the kind of thing that could easily break an application on another platform.

Why the hell is the point (x,y) not acceptable by viewtomodel by itself? Is it the outside of the application that is supperimposing itself to the viewport, and the getX method doesn't take it in stride? How can i garantee that it is the last point in the viewport?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!