Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win


SWT Text : Select part of the text?

Posted on 2011-02-14
Medium Priority
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
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 2
  • +1
LVL 26

Expert Comment

ID: 34886754
in swings,

textField.select( 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?
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


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 500 total points
ID: 34887085

control.setSelection(t.length() - 3, t.length() - 1 );

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 1000 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 500 total points
ID: 34892043
it should be setSelection(3,5)
does selectAll() show it selected?
LVL 47

Assisted Solution

for_yan earned 1000 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

Enroll in October's Free Course of the Month

Do you work with and analyze data? Enroll in October's Course of the Month for 7+ hours of SQL training, allowing you to quickly and efficiently store or retrieve data. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

610 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