browseButton = new Button(controlGroupForSingleRun, SWT.PUSH);
browseButton.setText("Browse ...");
data = new GridData();
data.widthHint = 80;
browseButton.setLayoutData(data);
browseButton.addSelectionListener(new SelectionListener(){
public void widgetSelected(SelectionEvent event){
lookForExeClick();
}
public void widgetDefaultSelected(SelectionEvent event){
widgetSelected(event);
}
});
此代码在Eclipse插件GUI上生成一个浏览按钮,如何使此按钮只选择一个目录而不是特定的文件。现在它正在选择一个文件。有人可能会向我提供修改过的代码以允许这种情况发生。谢谢。此代码创建一个浏览按钮以选择一个文件。我如何更改它以允许我选择文件夹而不是文件夹内的文件
这里要求的是lookforExClick()方法。
So I changed the filedialog to directorydialog as the answer below mentioned. But here is my method you asked for:
private void lookForExeClick(){
boolean notLegal = false;
while(!notLegal){
exeChooser.setText("Choose an executable file");
singleExeFilePath = exeChooser.open();
String tmp = exeChooser.getFileName();
if(tmp.equals("")){
notLegal = true;
return;
}
else if(tmp == null){
notLegal = true;
return;
}
if(!tmp.equals("") && !tmp.endsWith(".exe") && !tmp.endsWith(".bat") && !tmp.endsWith(".jar")){
MessageDialog.openInformation(
window.getShell(),
"Vulnerabilities Viewer",
"Please input a legal executable name!"
);
}
else {
notLegal = true;
}
}
exeLocationText.setText(singleExeFilePath);
pureExeFileName = exeChooser.getFileName();
// Set selection to newLocation.
last.setSelection(false);
for(int i = 0; i < radios.length; i++){
radios[i].setSelection(false);
}
newLocation.setSelection(true);
}
我该如何取出或发表评论才能使浏览按钮适用于目录选择。请帮帮我。谢谢。
您显示的代码不会选择任何内容,请向我们展示“lookForExeClick”方法,其中我假设实际做了选择。 – 2015-04-01 07:16:24
按要求我添加了方便您的方法。 – 2015-04-02 02:09:16