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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T09:04:39+00:00 2026-06-16T09:04:39+00:00

http://git.eclipse.org/c/platform/eclipse.platform.swt.git/tree/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet2.java I am trying in SWT to add sorting to a table widget. Copying

  • 0

http://git.eclipse.org/c/platform/eclipse.platform.swt.git/tree/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet2.java

I am trying in SWT to add sorting to a table widget. Copying the code from Snippet2 sortListener Handler doesn’t work. It correctly swaps two items into sorted order. More than 2 items in the table, and the results are unpredictable.

It seems to me (in the following code extract from Snippet2 sortListener) that items[i].dispose() is going to change the array of TableItems called items that we are iterating over in the outer for loop, for (int i = 1 ...... Also, when one item is disposed(), and inserted into items at a new index, the whole array is recreated afresh. That surely breaks the iteration?

So, I guess I have two questions:

  1. What am I not understanding about Snippet2’s algorithm?
  2. Is there any other obvious reason why a sort operation might return random results (bearing in mind I am a noob, so am likely to have made the stupidest of mistakes)?

Here is my code:

Listener sortListener = new Listener() {
    public void handleEvent(Event e) {
        TableItem[] items = table.getItems();
        Collator collator = Collator.getInstance(Locale.getDefault());
        TableColumn column = (TableColumn)e.widget;
        int index = column == column1 ? 0 : 1;
        for (int i = 1; i < items.length; i++) {                <--------- HERE
            String value1 = items[i].getText(index);
            for (int j = 0; j < i; j++){
                String value2 = items[j].getText(index);
                if (collator.compare(value1, value2) < 0) {
                    String[] values = {items[i].getText(0), items[i].getText(1)};
                    items[i].dispose();                         <--------- HERE
                    TableItem item = new TableItem(table, SWT.NONE, j);
                    item.setText(values);
                    items = table.getItems();                   <--------- HERE

                    break;
                }
            }
        }
        table.setSortColumn(column);
    }
};
  • 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-16T09:04:40+00:00Added an answer on June 16, 2026 at 9:04 am

    You may want to use JFace wrapper for SWT table (org.eclipse.jface.viewers.TableViewer), which gives your table more built in features. I suggest this tutorial for JFace TableViewer. Here is tutorial for sorting TableViewer.

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

Sidebar

Related Questions

I tried the instructions of building latest QT5-Alpha(http://qt-project.org/wiki/Qt-5-Alpha http://qt-project.org/wiki/Building_Qt_5_from_Git ) from GIT,but facing compilation
I'm trying to host a Git repo using Nginx 0.8.52, with fcgiwrap wrapping git-http-backend
I'm trying to setup the CloudBees Eclipse Toolkit to connect to my CloudBees Git
I'm trying to access a private remote SSH git repository via the Eclipse 'egit'
Here's are examples of git workflows: https://github.com/bard/sameplace/wiki/typical-git-workflow http://www.nabble.com/Git-workflow-overview-td16340337.html http://osteele.com/archives/2008/05/my-git-workflow Let's say you wanted to
I am trying to setup git on my Mac through this link ( http://help.github.com/mac-set-up-git/
So, reading http://git-scm.com/book/en/v1/Git-on-the-Server-Public-Access , I'm trying to setup a bare repo as instructed on
I am using http://nvie.com/posts/a-successful-git-branching-model/ As far as I understand, main repo in this model
I installed Socat to use the Git Protocol Through a HTTP CONNECT Proxy, then
I am using 'git' to checkout chromium code by following this document: http://code.google.com/p/chromium/wiki/UsingGit And

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.