Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > JTextField, how to display from specified postions

Reply
Thread Tools

JTextField, how to display from specified postions

 
 
John_Woo
Guest
Posts: n/a
 
      08-21-2006
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

 
Reply With Quote
 
 
 
 
Roland de Ruiter
Guest
Posts: n/a
 
      08-21-2006
On 21-8-2006 20:49, John_Woo wrote:
> 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
>


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.
--
Regards,

Roland
 
Reply With Quote
 
 
 
 
John_Woo
Guest
Posts: n/a
 
      08-21-2006

Roland de Ruiter wrote:
> On 21-8-2006 20:49, John_Woo wrote:
> > 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
> >

>
> 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.
> --
> Regards,
>
> 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

 
Reply With Quote
 
Roland de Ruiter
Guest
Posts: n/a
 
      08-21-2006
On 21-8-2006 21:41, John_Woo wrote:
> Roland de Ruiter wrote:
>> On 21-8-2006 20:49, John_Woo wrote:
>>> 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
>>>

>> 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.
>> --
>> Regards,
>>
>> 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
>

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();
}
--
Regards,

Roland
 
Reply With Quote
 
John_Woo
Guest
Posts: n/a
 
      08-21-2006

Roland de Ruiter wrote:
> On 21-8-2006 21:41, John_Woo wrote:
> > Roland de Ruiter wrote:
> >> On 21-8-2006 20:49, John_Woo wrote:
> >>> 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
> >>>
> >> 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.
> >> --
> >> Regards,
> >>
> >> 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
> >

> 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();
> }
> --
> Regards,
>
> 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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
The specified display mode is currently disabled on this page. Make alcatraz ASP .Net 1 04-01-2008 05:36 PM
front panel header postions Marty Computer Support 5 05-22-2006 08:21 PM
How to display a string in many lines, each lines have a specified length thuyptt@dsp.com.vn C++ 1 12-06-2005 07:26 AM
enum: display elements of an enum specified at runtime Jerminia Java 3 10-07-2005 10:08 PM



Advertisments