浏览按钮在 Java 中的文本框中不显示文件路径



我创建了一个浏览按钮,下面是代码:

private void lookForExeClick () throws FileNotFoundException{
    DirectoryDialog dlg = new DirectoryDialog(Display.getCurrent().getActiveShell());
    String directoryPath = dlg.open();
    //File file = new File(directoryPath, "MyFileName.txt");
    //FileOutputStream outputStream = new FileOutputStream(file);

我在 gui 上创建的文本框是这样的:

    exeLocationText = new Text(controlGroupForSingleRun, SWT.BORDER);
    exeLocationText.setText("");
    data = new GridData();
    data.widthHint = 265;
    exeLocationText.setLayoutData(data);

单击浏览到我在 Java 中创建的文本框后,如何获取我在目录对话框中选择的文件路径。 任何建议都会有所帮助。 谢谢。

在点击处理程序中,您只需要:

String directoryPath = dlg.open();
if(directoryPath != null)
  exeLocationText.setText(directoryPath);

最新更新