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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T10:07:21+00:00 2026-06-15T10:07:21+00:00

I have a method in my SWT class that gets the selected value from

  • 0

I have a method in my SWT class that gets the selected value from my table. The value is actually the file name of the object.

 public String getPDFFileName() { 
    int row = viewer.getTable().getSelectionIndex();
    if (row != -1) {
       return pdfFileName = AplotSaveDataModel.getInstance().getSelectedPDFFileName(row);
    }
    else {
       MessageDialog.openError(null, "PDF Selection Error Message", "You need to select a PDF to view.");
    }
    return null;
  }

I have a composite in the same class that is bridging SWT and Swing. This method takes the String Filename and creates a Swing Viewer displaying the file.

 protected Control createPDFButtons(Composite parent) {
  final Composite swtAwtComponent = new Composite(parent, SWT.EMBEDDED);
  GridData mainLayoutData = new GridData(SWT.FILL, SWT.CENTER, true, false); 
  mainLayoutData.horizontalSpan = 1; 
  swtAwtComponent.setLayoutData(mainLayoutData); 
  GridLayout mainLayout = new GridLayout(1, false); 
  mainLayout.marginWidth = 0; 
  mainLayout.marginHeight = 0; 
  swtAwtComponent.setLayout(mainLayout); 
  final Frame frame = SWT_AWT.new_Frame(swtAwtComponent);
  final JPanel panel = new JPanel();
  panel.setLayout(new BoxLayout(panel, BoxLayout.X_AXIS)); 

  JButton viewerButton = new JButton("View Selected PDF");
  viewerButton.addActionListener(new ActionListener(){
     public void actionPerformed(ActionEvent actionevent) {

        final File viewerFile = new File(getPDFFileName());
        final AplotPdfViewer pdfv = new AplotPdfViewer(true);
        try {
           pdfv.openFile(viewerFile);
        }
        catch (IOException e) {
           e.printStackTrace();
        }

     }
  });

  panel.add(viewerButton);
  frame.add(panel);
  return swtAwtComponent;
}      

If I try and run the getPDFFileName() in the composite, I get a SWT thread error. I understand where that comes from.

I am not sure how to get the value from getPDFFileName() and use it in final File viewerFile = new File(“NEED FILENAME OF SELECTION”);

  • 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-15T10:07:22+00:00Added an answer on June 15, 2026 at 10:07 am

    You need to be a UI Thread when you try to access a widget (in your case the Table). You can do it using Display.syncExec

      JButton viewerButton = new JButton("View Selected PDF");
      viewerButton.addActionListener(new ActionListener(){
         public void actionPerformed(ActionEvent actionevent) {
            // Retrieve the pdf file name in the UI thread
            final String[] filename = new String[1];
            Display.getCurrent().syncExec(new Runnable() { 
                public void run() {
                    filename[0] = getPDFFileName();
                }
            }
    
            final File viewerFile = new File(filename[0]);
            final AplotPdfViewer pdfv = new AplotPdfViewer(true);
            try {
               pdfv.openFile(viewerFile);
            }
            catch (IOException e) {
               e.printStackTrace();
            }    
         }
      });
    

    Consider to put the call to syncExec directly in the getPDFFileName method if it’s needed several times. The String result is saved in an array because you can’t return a result with syncExec.

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

Sidebar

Related Questions

I have method that returns module path of given class name def findModulePath(path, className):
I have a button that runs a method. The method gets the selected Rows
I have method that returns Drawable , and if its Bitmap object is recycled
I have method in a class that I need to make sure is only
I have method to compress file with GZip: public static void CompressFile(string filePath) {
I have method that does asynchronous call to web service. Something like that: public
I have a method that accepts only a String. public void setVerticalAlignment(String align) {
I have method that returned NSManagedObject and I don't know what kind of NSManagedObject
I've got some 3rd party beans that have method signatures that fit quite well
I have this method which lets me translate the position of an object, animating

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.