相关疑难解决方法(0)

将JFileChooser置于所有窗口之上

我似乎对我的文件选择器对话的非常简单的实现有一个问题,这需要我每次都要最小化Netbeans才能到达它,并且特别是现在通过测试它变得非常令人沮丧.

我已经在网上看到了一些解决方案,包括SO,但似乎没有一个可以做到这一点,而其他一些解决方案对我目前的水平看起来非常冗长和复杂.

private void fileSearch() {

    JFileChooser fileSelect = new JFileChooser();
    int returnVal = fileSelect.showOpenDialog(null);
    String pathToFile;

    if (returnVal == JFileChooser.APPROVE_OPTION) {
        File file = fileSelect.getSelectedFile();
        pathToFile = file.getAbsolutePath();
        try {
            P.binaryFileToHexString(pathToFile);
        } catch (Exception e) {
            System.out.print("Oops! there was an error there..." + e);
        }
        System.out.println("\nYou chose to open this file: " + file.getName());
    }
}
Run Code Online (Sandbox Code Playgroud)

我的一些尝试包括使用;

.requestFocus();
.requestFocusInWindow();
.setVisible();
Run Code Online (Sandbox Code Playgroud)

我可以设置一个特定的属性/方法来解决问题吗?

java swing jfilechooser openfiledialog

19
推荐指数
2
解决办法
2万
查看次数

使用Nimbus LAF的Mac键盘快捷键

有没有办法在OS X上使用Nimbus LAF(外观和感觉),同时仍然能够使用该Meta键进行剪切/复制/粘贴和选择所有操作?

我目前在我的Swing应用程序的main方法中有以下代码,它根据操作系统更改了LAF(OS X的默认值,所有其他的Nimbus):

if (!System.getProperty("os.name", "").startsWith("Mac OS X")) {
    try {
        for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
            if ("Nimbus".equals(info.getName())) {
                javax.swing.UIManager.setLookAndFeel(info.getClassName());
                break;
            }
        }
    } catch (ClassNotFoundException ex) {
        java.util.logging.Logger.getLogger(LicenseInspectorUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
    } catch (InstantiationException ex) {
        java.util.logging.Logger.getLogger(LicenseInspectorUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
    } catch (IllegalAccessException ex) {
        java.util.logging.Logger.getLogger(LicenseInspectorUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
    } catch (javax.swing.UnsupportedLookAndFeelException ex) {
        java.util.logging.Logger.getLogger(LicenseInspectorUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
    }
}
Run Code Online (Sandbox Code Playgroud)

我这样做是一种解决方法,因为Nimbus会覆盖在OS X上剪切/复制/粘贴和select-all的键盘快捷键(Meta键与Ctrl键).如果只是键盘快捷键没有被覆盖,我宁愿一直使用Nimbus.

java macos swing keyboard-shortcuts nimbus

5
推荐指数
1
解决办法
1151
查看次数