Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / August 2006

Tip: Looking for answers? Try searching our database.

JTextField, how to display from specified postions

Thread view: 
John_Woo - 21 Aug 2006 19:49 GMT
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


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.