|
From: Peter De B. <pet...@gm...> - 2007-09-07 11:00:10
|
Do something like this:
[code]
textComponent.getDocument().addDocumentListener( new
DocumentListener() {
public void removeUpdate( DocumentEvent e ) {
fixCaret();
}
public void insertUpdate( DocumentEvent e ) {
fixCaret();
}
public void changedUpdate( DocumentEvent e ) {
fixCaret();
}
private void fixCaret() {
if( !textComponent.hasFocus() ) {
// need to invoke later, as the text change also
changes the caret
// position
SwingUtilities.invokeLater( new Runnable() {
public void run() {
textComponent.setCaretPosition( 0 );
}
} );
}
}
} );
[/code]
On 9/7/07, Peter De Bruycker <pet...@gm...> wrote:
>
>
>
> On 9/7/07, Rogan Dawes <ro...@da...> wrote:
> >
> > Andy DePue wrote:
> > > If this is a Swing "feature", then I'm not aware of a simple setting
> > > somewhere (maybe someone else knows of one?). I do know that
> > > DefaultCaret has a setUpdatePolicy method. You would have to get the
> > > Caret from the JTextField, make sure it is a DefaultCaret, cast it to
> > > DefaultCaret, and invoke setUpdatePolicy(DefaultCaret.NEVER_UPDATE).
> > > Even then, I haven't tested this, so I'm not sure if it would have the
> >
> > > desired effect. Another approach would be to implement a
> > > FormComponentInterceptor that automatically handles any JTextField
> > that
> > > is not enabled so that the caret it always placed at the beginning of
> > > the field. See SelectAllFormComponentInterceptorFactory for an
> > example
> > > of what an interceptor looks like.
> > >
> > > - Andy
> >
> > How about calling
> >
> > http://java.sun.com/j2se/1.4.2/docs/api/javax/swing/text/JTextComponent.html#setCaretPosition(int)<http://java.sun.com/j2se/1.4.2/docs/api/javax/swing/text/JTextComponent.html#setCaretPosition%28int%29>
> >
> > with a value of 0 after setting the text?
>
>
>
> exactly,
>
> But what better place to do this than in a FormComponentInterceptor?
>
>
>
> Rogan
> >
> > -------------------------------------------------------------------------
> >
> > This SF.net email is sponsored by: Splunk Inc.
> > Still grepping through log files to find problems? Stop.
> > Now Search log events and configuration files using AJAX and a browser.
> > Download your FREE copy of Splunk now >> http://get.splunk.com/
> > _______________________________________________
> > Springframework-rcp-dev mailing list
> > Spr...@li...
> > https://lists.sourceforge.net/lists/listinfo/springframework-rcp-dev
> >
>
>
|