2

I have searched the web for quite a while now, and have not come across a simple solution for making a button, which opens a file browsing dialog in an Eclipse program. I am using WindowBuilder at the moment, and it seems odd to me, that one has to do so much to add a simple "Browse..." button to their GUI.

I hope someone can help me on this matter, thanks!

1 Answers1

1

I use this code:

 private Button browse;
   browse = new Button(outerGroup, SWT.PUSH);
        browse.setText("Browse ...");
        browse.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false,1,0));
        browse.addSelectionListener(new SelectionAdapter() {
            public void widgetSelected(SelectionEvent e) {
                DirectoryDialog dialog = new DirectoryDialog(shell, SWT.NULL);
                String path = dialog.open();
                if (path != null) {
                    //do stuff with path
                }
            }

        });
Fran Montero
  • 1,679
  • 12
  • 24