<Swing Dev> RFR: 4916923: In MetalRootPaneUI, MetalRootLayout does not correctly calculate minimumsize

Sergey Bylokhov serb at openjdk.java.net
Sat Oct 10 11:37:08 UTC 2020


On Thu, 8 Oct 2020 03:57:48 GMT, Prasanta Sadhukhan <psadhukhan at openjdk.org> wrote:

>> The MetalRootPaneUI installs the MetalRootLayout as a layout manager for the current JRootPane. And it should be used
>> from the Container.preferredSize()
>
> I tried following testcase snippet
>                ```
>  JRootPane r = new JRootPane();
>                 JFrame f = new JFrame();
>                 f.getRootPane().setUI(new MetalRootPaneUI());
>                 f.getRootPane().setWindowDecorationStyle(JRootPane.FRAME);
>                 f.getRootPane().getUI().installUI(r);
>                 r.getContentPane().add(new JLabel("foo"));
>                 System.out.println("Preferred Size: " + r.getPreferredSize());
> but it uses JRootPane.RootLayout layout manager and not MetalRootLayout so it calls Rootlayout.preferredLayoutSize and
> not MetalRootLayout.preferredlayoutSize

You need to set decorations for the root pane:
        UIManager.setLookAndFeel(new MetalLookAndFeel());
        JFrame frame = new JFrame();
        frame.getRootPane().setWindowDecorationStyle(JRootPane.FRAME);
        frame.pack();
        System.out.println("Layout: " + frame.getRootPane().getLayout());
========
Layout: javax.swing.plaf.metal.MetalRootPaneUI$MetalRootLayout at 69d9c55

-------------

PR: https://git.openjdk.java.net/jdk/pull/433


More information about the swing-dev mailing list