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

  • Home
  • SEARCH
  • 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 8541139
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T11:45:46+00:00 2026-06-11T11:45:46+00:00

I have a button that runs a method. The method gets the selected Rows

  • 0

I have a button that runs a method. The method gets the selected Rows in the table and adds them to an arraylist. This works well the first time executed. But if the user selected the wrong row, they will be able to re select a different row and add that selection data to the arraylist.

But with my current the code, it does not matter what row the user selects the second time the first selected data is always added to the arraylist. It is like the selection needs to be reset or refreshed before the user selects the new row.

Button Code

Button pdfButton = new Button(composite, SWT.PUSH);
   pdfButton.setText("Get Plotter List");
   pdfButton.setEnabled(true);
   pdfButton.addSelectionListener(new SelectionAdapter() {
       public void widgetSelected(SelectionEvent e) {
          getPlotterSelection();
       }
   }); 

Method Code

 public void getPlotterSelection() {
    selectedPlotters.clear(); <-- Clearing the ArrayList
    int[] row = viewer.getTable().getSelectionIndices(); <-- Getting Current Selections
    Arrays.sort(row);

    if (row.length > 0) {
       for(int i = row.length-1; i >= 0; i--){
          PrinterProfile pp = new PrinterProfile(aa.get(i).getPrinterName(), aa.get(i).getProfileName());
          selectedPlotters.add(pp);
        }
     }
     viewer.getTable().deselectAll();
   }

As I am writing this, I think maybe the problem is in the getSelectionIndices(). It seems to be getting the number of rows selected, but not the actual row number

Edit

The problem was in my logic. I was getting the correct Indices but using i varaible in the for loop to get the value.

for(int i = row.length-1; i >= 0; i--){
          PrinterProfile pp = new PrinterProfile(aa.get(i).getPrinterName(), aa.get(i).getProfileName());

changed it to

aa.get(row[i].getPrinterName(), etc...

and it works like I thought it would

  • 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-11T11:45:47+00:00Added an answer on June 11, 2026 at 11:45 am

    Since you are already using a TableViewer, why not get the selection from it?

    IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
    YourObject[] array = (YourObject[])selection.toArray();
    

    Then you can iterate over the array and add them to your ArrayList.

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

Sidebar

Related Questions

I currently have a delayed task that runs whenever I click a button. Clicking
I have a jQuery question: I have an ADD button that adds text to
I have a Winforms App (.NET 3.X) That runs a method in a class
I have a small WPF application. This application has a button that when clicked,
All, I have a mathod called TaskSpin that runs the passed method on a
Say I have a windows service that runs a method to generate reports. For
Basically, I have a button that when you press it, it runs its action
I have button that a user selects and I pop up a AlertDialog to
I have a button that can have a focus css class associated with it
I have event Button that creates text box in run time. Private Sub Button1_Click(ByVal

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.