Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8740603
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T11:09:28+00:00 2026-06-13T11:09:28+00:00

I have a class of this type org.eclipse.swt.widgets.Text . It lives inside of an

  • 0

I have a class of this type org.eclipse.swt.widgets.Text. It lives inside of an eclipse plugin I am developing. I want to handle the event where the user selects text from within this field. That is… while focused, they click into some text and drag either left or right to select text. When this text is selected, that is when I need to fire my event.

I am yet unable to find the appropriate listener to cover my need.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T11:09:29+00:00Added an answer on June 13, 2026 at 11:09 am

    I think SWT.MouseUp is the event you are looking for. If you want to check “arrow keys and shift selection”, listen to SWT.KeyUp as well and check the keyCode of the event:

    public static void main(String[] args) {
        final Display display = new Display();
        final Shell shell = new Shell(display);
        shell.setLayout(new GridLayout(1, false));
    
        Text text = new Text(shell, SWT.BORDER);
        text.setText("BLABLABLA");
    
        text.addListener(SWT.MouseUp, new Listener() {
    
            @Override
            public void handleEvent(Event event) {
                Text text = (Text) event.widget;
    
                String selection = text.getSelectionText();
    
                if(selection.length() > 0)
                {
                    System.out.println("Selected text: " + selection);
                }
            }
        });
    
        text.addListener(SWT.KeyUp, new Listener() {
    
            @Override
            public void handleEvent(Event event) {
                Text text = (Text) event.widget;
    
                String selection = text.getSelectionText();
    
                if(selection.length() > 0 && event.keyCode == SWT.SHIFT)
                {
                    System.out.println("Selected text: " + selection);
                }
            }
        });
    
        shell.pack();
        shell.open ();
        while (!shell.isDisposed ()) {
            if (!display.readAndDispatch ()) display.sleep ();
        }
        display.dispose ();
    }
    

    This code will only print the selection, if the user really selected something. If it’s a mouse-up o key-up without selection, nothing will happen.

    You might want to combine both in one listener to save space.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a class like this: abstract class CrudResource extends Controller { type ResourceIdType
For example, i have this: class BasePacket { int header; int type; } class
I have a generic class that takes a type T . Within this class
Lets say have this immutable record type: public class Record { public Record(int x,
I have a class this is annotated with @Path like so: @Path(widgets) @Produces(MediaType.APPLICATION_XML) public
I have a class like this (it's a java class in eclipse, under a
I have this jQuery script var dataString = class_id=+class_id; $.ajax({ type: POST, url: page.php,
I have class like this below shown. which contains the shopping items where the
I have class that looks like this: class A { public: class variables_map vm
I have a class that inherits from a base class (this contains a lot

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.