Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » How to determine line number/caret position
How to determine line number/caret position [message #443312] Wed, 22 September 2004 12:44 Go to next message
Hermann Platzer is currently offline Hermann PlatzerFriend
Messages: 4
Registered: July 2009
Junior Member
I have a StyledText widget and want to display in a separate label the
actual line number and caret position.
Which listener is to use resp is there somewhere a code snippet?

Best regards,
Hermann
Re: How to determine line number/caret position [message #443316 is a reply to message #443312] Wed, 22 September 2004 14:36 Go to previous messageGo to next message
Rob Warner is currently offline Rob WarnerFriend
Messages: 9
Registered: July 2009
Junior Member
You can use a key listener:

styledText.addKeyListener(new KeyAdapter() {
public void keyPressed(KeyEvent event) {
// Update your label
}
});

Use styledText.getCaretOffset() to get the caret position.
Use styledText.getLineAtOffset(caretOffset) to get the line number.
Remember that the returned line number is zero-based, so you'll probably
want to add 1.

Hermann Platzer wrote:

> I have a StyledText widget and want to display in a separate label the
> actual line number and caret position.
> Which listener is to use resp is there somewhere a code snippet?

> Best regards,
> Hermann
Re: How to determine line number/caret position [message #443353 is a reply to message #443316] Thu, 23 September 2004 06:46 Go to previous message
Hermann Platzer is currently offline Hermann PlatzerFriend
Messages: 4
Registered: July 2009
Junior Member
Thanks - that works fine!
I've tried a VerifyKeyListener, but the counts are not correct in all
situations ... (Eclipse 2.1.0)


Rob Warner wrote:

> You can use a key listener:

> styledText.addKeyListener(new KeyAdapter() {
> public void keyPressed(KeyEvent event) {
> // Update your label
> }
> });

> Use styledText.getCaretOffset() to get the caret position.
> Use styledText.getLineAtOffset(caretOffset) to get the line number.
> Remember that the returned line number is zero-based, so you'll probably
> want to add 1.

> Hermann Platzer wrote:

> > I have a StyledText widget and want to display in a separate label the
> > actual line number and caret position.
> > Which listener is to use resp is there somewhere a code snippet?

> > Best regards,
> > Hermann
Previous Topic:Does the setters in FileDialog accept regular expressions?
Next Topic:Centering buttons with an without vertical scrollbar
Goto Forum:
  


Current Time: Wed Sep 18 19:58:20 GMT 2024

Powered by FUDForum. Page generated in 0.03715 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top