SWT Text : Select part of the text?

Posted on 2011-02-14
Last Modified: 2012-05-11
I have a textbox which I want to select the last two characters of.

So for example:


I would like to select the 00 only.

Question by:directxBOB
  • 4
  • 3
  • 2
  • +1
LVL 26

Expert Comment

ID: 34886754
in swings, 3, 4 ) ;

Author Comment

ID: 34886892
I don't seem to have a select option. I have selectAll, setSelection
LVL 26

Expert Comment

ID: 34886896
what are the params for setSelection?

Author Comment

ID: 34886921
int Start
Point selection
int Start, int End

I've tried

control.setSelection(0, t.length());
LVL 26

Accepted Solution

ksivananth earned 125 total points
ID: 34887085

control.setSelection(t.length() - 3, t.length() - 1 );
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).


Author Comment

ID: 34887471
That doesn't appear to have done anything

It could be a timing issue, but  not really sure.
LVL 47

Assisted Solution

for_yan earned 250 total points
ID: 34890543
With Text components
it actually does selection either selectAll(), or with like setSelection(2,4) , so that you can then get selected text later correctly,
but it does not show it.
If you want selection to be shown use
StyledText components insted of Text components.
Those will show selected text in blue - and you can of course change how it shows selection.
LVL 92

Assisted Solution

objects earned 125 total points
ID: 34892043
it should be setSelection(3,5)
does selectAll() show it selected?
LVL 47

Assisted Solution

for_yan earned 250 total points
ID: 34892262
At least for me it does not show selection - neither selectAll, nor setSelection(..)
Only wheh I changed to StyledText did it start showing
When I retrieve getSelection - it still retrieves seletced part from both


Author Closing Comment

ID: 35279124
For some reason my application simply was not allowing any of these selects to work. The application has been scrapped and onto another one now... sorry about not getting back, work has been insane.

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
countHi challenge 25 84
Unable to open debugger port in Intellij idea 6 84
base64 decode encode 12 96
Java Jpanels and Jframe 8 20
INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now