2

I'm working on an application that makes use of Swing's JInternalFrame. I'm using the native look and feel with UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());.

However, the native look and feel for the internal frame remains in the Windows Vista/7 style while running on a Windows 10 machine. With the example code from this bug report, I get the following result (with both JDK 8 and JDK 10):

JInternalFrame on Windows 10

I assume the styling supplied with Swing hasn't been updated in a long time, so there is no intended way to style the internal frame like a native window on systems newer than Vista. Is there a possible workaround instead?

Appleshell
  • 7,088
  • 6
  • 47
  • 96
  • A workaround is possible but complicated. You need to provide your own `InternalFrameUI`. This means, that you need to paint the title bar and border by yourself. Then you need to update the UI for internal frame using `UIManager.put("InternalFrameUI", MyWindows10UI.class.getName());` – Sergiy Medvynskyy Sep 10 '18 at 10:12
  • I have the same problem. I tried on Windows Server 12 R2 and the rendering is still working on Java 8. On my clients with Win 10 and Java 8 I experienced the same as you :( – Csaba Tenkes Apr 28 '19 at 12:29

1 Answers1

1

In this situation it is good to inspect the UIManager's theme:

    JFrame.setDefaultLookAndFeelDecorated(true);
    Object[] keys = UIManager.getLookAndFeel().getDefaults().keySet().toArray();
    Arrays.sort(keys, Comparator.comparing(Object::toString));
    for (int i = 0; i < keys.length; i++) {
        if (keys[i].toString().startsWith("InternalFrame.")) {
            System.out.println(keys[i] + " : " + javax.swing.UIManager.getDefaults().get(keys[i]));
        }
    }

You'll find the following keys:

    "InternalFrame.closeIcon"
    "InternalFrame.iconifyIcon"
    "InternalFrame.maximizeIcon"
    "InternalFrame.minimizeIcon"

Then create 4 transparent .png icons for close, iconify, maxize/minimize.

private void setInternalFrameIcon(String uiKey, String resource) {
    ImageIcon icon = new ImageIcon(getClass().getResource(resource));
    UIManager.put(uiKey, close);
}

    setInternalFrameIcon("InternalFrame.closeIcon", "... .png");
    setInternalFrameIcon("InternalFrame.iconifyIcon", "... .png");
    setInternalFrameIcon("InternalFrame.maximizeIcon", "... .png");
    setInternalFrameIcon("InternalFrame.minimizeIcon", "... .png");
Joop Eggen
  • 107,315
  • 7
  • 83
  • 138