under what condition "setViewPosition" may not work?
From: Kaidi (kaidizhao_at_yahoo.com.sg)
Date: 11/20/04
- Next message: Babu Kalakrishnan: "Re: Adding global keys to application"
- Previous message: hiwa: "Re: javax.swing.text.HTMLDocument getIterator returns null for some Tags"
- Next in thread: John McGrath: "Re: under what condition "setViewPosition" may not work?"
- Reply: John McGrath: "Re: under what condition "setViewPosition" may not work?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 19 Nov 2004 21:04:12 -0800
Hello guys,
I have a rather strange question about setViewPosition (in
JScrollPane), it seems not working sometimes under certain conditions,
but I can not find out the reason. My program is doing something like:
There is a:
OperateVisPanelDrawBoard jPanelDrawBoard = new
OperateVisPanelDrawBoard();
The OperateVisPanelDrawBoard is "extends JPanel", with only two
functions, one is paintComponent(Graphics g) where I draw out some
dots and lines on the JPanel, one is getPreferredSize() where it
return the preferredSize (the boundary of those dots and lines drawn).
And there is a:
JScrollPane jScrollPaneDraw =
new JScrollPane(jPanelDrawBoard,
ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,
ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
jScrollPaneDraw.setAutoscrolls(true);
The question is in a piece of code like:
// when user clicks the mouse, it draws out some dots and lines
and my code udpates the jPanelDrawBoard, and the scrool pane(bars)'s
view is also updated by calling the setViewPosition.
.....
Point nodePos=new .........;
System.out.println("View port pos: "+nodePos.toString());
jScrollPaneDraw.getViewport().setViewPosition(nodePos);
Point p2=jScrollPaneDraw.getViewport().getViewPosition();
System.out.println("View port pos: "+p2.toString());
System.out.println();
......
I suppose the two println above should return same value. But
sometimes the values are different! It seems the setViewPosition does
not work sometimes.
Some output I get may look like:
View port pos: java.awt.Point[x=658,y=576]
View port pos: java.awt.Point[x=658,y=576]
View port pos: java.awt.Point[x=1034,y=1540]
View port pos: java.awt.Point[x=1034,y=1244]
View port pos: java.awt.Point[x=2402,y=3478]
View port pos: java.awt.Point[x=2402,y=2244]
See the last two ones, the y values are different. :-(
Any idea of why this happen? Under what conditions will
setViewPosition refuse to work?
PS: this part of code is in single (main) thread.
Thanks a lot and nice weekend. :-)
- Next message: Babu Kalakrishnan: "Re: Adding global keys to application"
- Previous message: hiwa: "Re: javax.swing.text.HTMLDocument getIterator returns null for some Tags"
- Next in thread: John McGrath: "Re: under what condition "setViewPosition" may not work?"
- Reply: John McGrath: "Re: under what condition "setViewPosition" may not work?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]