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 1110345
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T02:22:53+00:00 2026-05-17T02:22:53+00:00

Using the Eclipse SWT StyledText widget, how can you indent/un-indent a selected block of

  • 0

Using the Eclipse SWT StyledText widget, how can you indent/un-indent a selected block of text with the tab or shift+tab keys?

  • 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-05-17T02:22:54+00:00Added an answer on May 17, 2026 at 2:22 am

    This seems to do the trick…

    protected Control createContents(Composite parent){
        ......
        //add the listeners...
        text_code_impl.addVerifyKeyListener(new VerifyKeyListener() { 
            public void verifyKey(VerifyEvent e) { 
                if (e.keyCode == SWT.TAB) {
                    if ((e.stateMask & SWT.SHIFT) != 0){
                        e.doit = text_code_impl_shift_tab_pressed();
                    } else {
                        e.doit = text_code_impl_tab_pressed();
                    }
                }
            }
        });         
        text_code_impl.addTraverseListener(new TraverseListener() { 
            public void keyTraversed(TraverseEvent e) { 
                if (e.detail == SWT.TRAVERSE_TAB_PREVIOUS) {
                    e.doit = false; //allows verifyKey listener to fire
                }
            } 
        });
    } 
    
    boolean text_code_impl_tab_pressed()
    {
        if (text_code_impl.getSelectionText().equals("")){
            return true;
        }
    
        Point range = text_code_impl.getSelectionRange(); 
        int start = range.x; 
        int length = text_code_impl.getSelectionCount(); 
    
        String txt = text_code_impl.getText();
        while (start > 0 && txt.charAt(start-1) != '\n') { 
            start--; 
            length++; 
        } 
    
        int replace_length = length;
        text_code_impl.setSelectionRange(start, length);
        text_code_impl.showSelection();
    
        String sel_text = text_code_impl.getSelectionText();
        String[] lines = sel_text.split("\n");
        String new_text = "";
    
        for (int x=0; x < lines.length; x++){
            if (x > 0){
                new_text += '\n';
            }
            new_text += '\t';
            length++;
            new_text += lines[x];
        }
    
        text_code_impl.replaceTextRange(start, replace_length, new_text); 
        text_code_impl.setSelectionRange(start, length);
        text_code_impl.showSelection();
    
        return false;
    }
    
    boolean text_code_impl_shift_tab_pressed()
    {
        if (text_code_impl.getSelectionText().equals("")){
            return true;
        }
    
        Point range = text_code_impl.getSelectionRange(); 
        int start = range.x; 
        int length = text_code_impl.getSelectionCount(); 
    
        String txt = text_code_impl.getText(); 
        while (start > 0 && txt.charAt(start-1) != '\n') { 
            --start; 
            ++length; 
        } 
    
        int replace_length = length;        
        text_code_impl.setSelectionRange(start, length);
        text_code_impl.showSelection();
    
        String sel_text = text_code_impl.getSelectionText();
        String[] lines = sel_text.split("\n");
        String new_text = "";
    
        for (int x=0; x < lines.length; x++){
            if (x > 0){
                new_text += '\n';
            }
            if (lines[x].charAt(0) == '\t'){
                new_text += lines[x].substring(1);
                length--;
            } else if (lines[x].startsWith(" ")){
                new_text += lines[x].substring(1);
                length--;
            } else {
                new_text += lines[x];
            }
        }   
    
        text_code_impl.replaceTextRange(start, replace_length, new_text); 
        text_code_impl.setSelectionRange(start, length);
        text_code_impl.showSelection();
    
        return false;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using org.eclipse.swt.widgets.Text 's type of Text field. I want to increase the
I'm using Eclipse to write a java application. My application includes a DateTime widget
How do I build an SWT application using the Eclipse P2 repository and the
In eclipse RCP, there is SWT Browser Widget to render HTML and Javascript. I
I'm developing an Eclipse SWT application using Eclipse. There are also some JUnit 4
Right now i've written a simple SWT application using eclipse, and I want to
I m testing a eclipse plugin using swt bot.but I cant find a way
I'm using StyledText component which behaves somewhat similar to the popular eclipse IDE console
I am trying to create a Hello World SWT application using Eclipse. I follow
I am writing an application in Java for the desktop using the Eclipse SWT

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.