【问题标题】:Test Program in Windows Environment on OS X在 OS X 上的 Windows 环境中测试程序
【发布时间】:2016-01-27 23:47:04
【问题描述】:

我注意到一些奇怪的行为,这实际上是由于使用 Mac OS X 或 Windows 时 JFileChooser 的布局不同造成的。

在我的 Mac 上,窗口如下所示:

而在 Windows 上则如下所示:

我的问题是:有没有机会在我的 Mac 上模拟 Windows 外观?因为我没有 Windows 电脑,所以我无法测试任何更改,但总是要等待其他人测试它,这当然是非常缓慢的,因为它只是一个参数化的问题。

public DelimiterFileChooser(String[] comboChoices) {
    comboBox = new JComboBox<>();
    comboBox.setModel(new DefaultComboBoxModel<String>(comboChoices));
    JPanel comboPanel = null;
    if (os.indexOf("mac") >= 0 || os.indexOf("nix") >= 0 || os.indexOf("nux") >= 0 || os.indexOf("aix") > 0) {
        comboPanel = (JPanel) this.getComponent(4);
        comboPanel = (JPanel) comboPanel.getComponent(2);
    } else {
        comboPanel = (JPanel) this.getComponent(3);
        comboPanel = (JPanel) comboPanel.getComponent(3);
    }
    Component c1 = comboPanel.getComponent(0);
    Component c2 = comboPanel.getComponent(1);
    comboPanel.removeAll();
    comboPanel.add(getPanel(new JLabel("Use delimiter for .csv:"), comboBox));
    comboPanel.add(c1);
    comboPanel.add(c2);
}

对于那些感兴趣的人,这是我的代码。我在another Stack Overflow thread 中找到了 Windows 部分,最初想知道为什么它在我的 Mac 上不起作用。现在我知道,显然对话框在不同的操作系统系统上的构建方式不同,我不再想知道,但是线程中建议的解决方案对我没有用。

【问题讨论】:

  • 为什么不在您的 Mac 上运行虚拟 Windows 机器?使用 Parallels、VMWare 还是免费的 VirtualBox?只需更改 L&F,即使 L&F 是真实的,仍然会为您提供 Mac 路径(您将无法看到或选择诸如 C:D: 等 Mac 上不存在的东西)。
  • 原来我的代码可以在虚拟机上正常运行。它看起来与我发布的最后一个链接中的完全一样。我会得到我问过它现在是否也适用于他们的人的反馈。如果没有,我可能无能为力。

标签: java windows macos jfilechooser look-and-feel


【解决方案1】:

如果您想在 OS-X 机器上运行 Windows,请尝试 VirtualboxVmWare FusionParallels。它使在 Mac 上运行(多个)Windows 版本变得容易。测试软件。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-06-29
    • 1970-01-01
    • 1970-01-01
    • 2013-01-01
    • 1970-01-01
    • 2010-10-10
    相关资源
    最近更新 更多