简体   繁体   中英

Can't remove border of JInternalFrame | Nimbus L&F

I've already done research on how to make a JInternalFrame show only its content without the borders.

Remove the top title bar: hiding title bar of JInternalFrame? -java

Remove the surrounding borders: how to remove the borders in JInternalFrame?

Everything works smoothly, until I tested my work with Numbus UI, I could get the title bar off, but the surrounding borders are stuck there:

在此处输入图片说明

The expected result (which works on other L&Fs) should be:

在此处输入图片说明

I assume there's some UI related setting that should solve it ( UIDefaults , or comp.putClientProperty() ); but I can't figure what it is.

With trial and error, I found a clean but still incomplete solution.

All I have to do is change the UI of the JInternalFrame to just any other. The new UI will not do any actual rendering, since I removed the title-bar and borders.

This solution is incomplete, DO NOT CALL anywhere in your code:

SwingUtilities.updateComponentTreeUI();

This will cause the internal frame to reset back to the default UI.


EDIT: Finally found a solution to the above reset problem. Just prevent Swing from installing any other than my custom set UI.

Using a subclass of JInternalFrame :

@Override
public void updateUI() {
        LookAndFeel laf = UIManager.getLookAndFeel();
        try {
            UIManager.setLookAndFeel(new javax.swing.plaf.metal.MetalLookAndFeel());
        } catch (UnsupportedLookAndFeelException e) {
        }

        super.updateUI();

        try {
            UIManager.setLookAndFeel(laf);
        } catch (UnsupportedLookAndFeelException e) {
        }
    }

This effectively ignores any change to set the UI, but I'm not happy with it. It resetsthe whole Look and Feel, and may cause race conditions which may cause unwanted LaF settings.

I'm still on the search for a solution, setting only this component to Metal.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM