Hi,
let's say
JTextField f = new JTextField(100);
f.setText( "more than 100 letters..| <inside is 100 letters end");
in a case setSize(400,200), or supposed the wide-size for this f is
just 100-letters length.
what displayed is that, f displays the 100 letters which backford from
the end of the string,
like "inside is 100 letters end";
I'm wondering, how to make it display from a specified postion?
I've tried
javax.swing.BoundedRangeModel m = f.getHorizontalVisibility();
m.setValueIsAdjusting(true);
m.setValue(10); //display from postion 10 to the end.
but it changed nothing.
--
Thanks
John
Toronto
Roland de Ruiter - 21 Aug 2006 20:25 GMT
> Hi,
>
[quoted text clipped - 26 lines]
> John
> Toronto
In these situations I've been using
f.setCaretPosition(0);
to "scroll" the field back to the beginning of the a very long text.
Of course setCaretPosition changes the position of the input caret. So
if you use f.setCaretPosition(10), a very long text just inserted into
the field would "scroll" back to the 10th character. Then when the user
types a character or digit on the keyboard (without using cursor keys
before), it will be inserted after the 10th character. Don't know if
this behavior/side-effect is what you want.

Signature
Regards,
Roland
John_Woo - 21 Aug 2006 20:41 GMT
> > Hi,
> >
[quoted text clipped - 41 lines]
>
> Roland
Thanks lots, it worked for me.
Can you tell why
javax.swing.BoundedRangeModel m = f.getHorizontalVisibility();
m.setValueIsAdjusting(true);
m.setValue(10); //display from postion 10 to the end.
not working?
John
Roland de Ruiter - 21 Aug 2006 21:40 GMT
>>> Hi,
>>>
[quoted text clipped - 52 lines]
>
> John
Seems to me a pixel offset rather than a character offset.
Method getHorizontalVisibility returns the same BoundedRangeModel
instance as the get/setScrollOffset methods are using. From the source
of JTextField:
public BoundedRangeModel getHorizontalVisibility() {
return visibility;
}
/**
* Gets the scroll offset, in pixels.
*
* @return the offset >= 0
*/
public int getScrollOffset() {
return visibility.getValue();
}

Signature
Regards,
Roland
John_Woo - 21 Aug 2006 22:12 GMT
> >>> Hi,
> >>>
[quoted text clipped - 73 lines]
>
> Roland
I changed by two ways:
A. f.setScrollOffset(10); //50, 100,1000, or
B. javax.swing.BoundedRangeModel m = f.getHorizontalVisibility();
m.setValueIsAdjusting(true);
m.setValue(10);//50,100,1000
the f.getScrollOffset() in both methods;
always return 0 and didn't display the first part of string
you know why?
Thanks
John