Does Swing support Windows 7-style file choosers?

前端 未结 10 2002
星月不相逢
星月不相逢 2020-11-28 08:26

I just added a standard \"Open file\" dialog to a small desktop app I\'m writing, based on the JFileChooser entry of the Swing Tutorial. It\'s generating a

10条回答
  •  無奈伤痛
    2020-11-28 09:17

    John McCarthy's answer seems to be the best. Here some suggestions.

    import org.eclipse.swt.*;
    import org.eclipse.swt.widgets.*;
    import org.eclipse.swt.graphics.Image;
    

    Add image on top left corner. It's important that you use "getResourceAsStream", you'll notice after export as Runnable jar:

    Display display = new Display();
    Shell shell = new Shell(display);
    InputStream inputImage = getClass().getResourceAsStream("/app/launcher.png");
    if (inputImage != null) {
        shell.setImage(new Image(display, inputImage));
    }
    

    User's home directory:

    String filterPath = System.getProperty("user.home");
    

    Get absolut pathname instead of filter-dependent pathname, which is wrong on other drive.

    String absolutePath = dialog.open();
    

提交回复
热议问题