0

I'm creating a MDI application with Netbeans, everything's working well as expected with the Look and Feel set to Nimbus.

Anytime I run the application, the JFrame and its toolbars use the specified L&F (Nimbus) but the Internal Frames use the cross platform (Metal) L&F making the application look shabby.

I want the Internal Frames to use the same L&F as the JFrame. Please how do I fix this?

I've tried calling JFrame.setdefaultlookandfeeldecorated(true) and SwingUtilities.updatecomponenttreeui(frame) but they didn't solve the problem.

mKorbel
  • 109,525
  • 20
  • 134
  • 319
  • 4
    1) For better help sooner, post an [SSCCE](http://sscce.org/). 2) *"I've tried calling .. `SwingUtilities.updatecomponenttreeui(frame)` but they didn't solve the problem."* That would not compile. – Andrew Thompson Nov 30 '12 at 09:16
  • @AndrewThompson I meant JFrame.setDefaultLookAndFeelDecorated(true) and SwingUtilities.updateComponentTreeUi(frame). The code compiles but doesn't fix the problem. – Jide Kolade Nov 30 '12 at 09:32
  • It's good you noticed the 2nd point. Now attend to the 1st. ;) – Andrew Thompson Nov 30 '12 at 11:04

1 Answers1

2

Anytime I run the application, the JFrame and its toolbars use the specified L&F (Nimbus) but the Internal Frames use the cross platform (Metal) L&F making the application look shabby.

enter image description here

import java.awt.Dimension;
import java.awt.EventQueue;
import javax.swing.*;
import javax.swing.UIManager.LookAndFeelInfo;

public class TestInternalFrame {

    public TestInternalFrame() {
        final JInternalFrame internal = new JInternalFrame("test");
        final JInternalFrame hidden = new JInternalFrame("test");
        hidden.setBounds(1000, 1000, 1, 1);
        hidden.setVisible(true);
        internal.setVisible(true);
        internal.setBounds(0, 0, 100, 100);
        JDesktopPane pane = new JDesktopPane();
        pane.add(internal);
        pane.add(hidden);
        pane.setPreferredSize(new Dimension(10000, 10000));
        final JFrame frame = new JFrame("Test");
        frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        frame.getContentPane().add(new JScrollPane(pane,
                JScrollPane.VERTICAL_SCROLLBAR_NEVER,
                JScrollPane.HORIZONTAL_SCROLLBAR_NEVER));
        /*frame.getContentPane().add(new JButton(new AbstractAction("Show blocked dialog") {

        private static final long serialVersionUID = 1L;

        @Override
        public void actionPerformed(ActionEvent e) {
        EventQueue.invokeLater(new Runnable() {

        @Override
        public void run() {
        JOptionPane.showInternalMessageDialog(hidden, "Hi 2!");
        }
        });
        JOptionPane.showInternalMessageDialog(internal, "Hi 1!");
        }
        }), BorderLayout.PAGE_END);*/
        frame.setPreferredSize(new Dimension(400, 300));
        frame.pack();
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);
    }

    public static void main(String[] args) {
        try {
            UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
            for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
                System.out.println(info.getName());
                if ("Nimbus".equals(info.getName())) {
                    UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (UnsupportedLookAndFeelException e) {
            // handle exception
        } catch (ClassNotFoundException e) {
            // handle exception
        } catch (InstantiationException e) {
            // handle exception
        } catch (IllegalAccessException e) {
            // handle exception
        }

        EventQueue.invokeLater(new Runnable() {

            @Override
            public void run() {
                TestInternalFrame tif = new TestInternalFrame();
            }
        });
    }
}
mKorbel
  • 109,525
  • 20
  • 134
  • 319
  • @mrKorbel Thank a lot, That's very similar to what I have, Netbeans adds the Look and Feel code for you but doesn't add the JFrame.setDefaultLookAndFeelDecorated(true) and SwingUtilities.updateComponentTreeUi(frame). I initially thought that could be the problem but even after adding them, It didnt fix the issue. Maybe it's Netbeans. Lol – Jide Kolade Nov 30 '12 at 12:24
  • I also tried changing the L&F to LiquidLookAndFeel, The JFrame's L&F changed quite alright but the Internal Frames were still stuck on Metal L&F. – Jide Kolade Nov 30 '12 at 12:26
  • @Jide Kolade only [Substance](http://stackoverflow.com/a/10909869/714968) can do that (correctly & proper way), to change a JFrames descorations (notice came from current theme applied in Native OS) – mKorbel Nov 30 '12 at 12:29
  • @mrKorbel only Substance? really? that doesn't feel right. I'll give it a shot though, Hope it fixes the problem. Thanx. – Jide Kolade Nov 30 '12 at 12:41
  • @Jide Kolade resources are injected from Native OS (decorations, color scheme, Fonts), its contents is pure Java (from RootPane, ContentPane), – mKorbel Nov 30 '12 at 12:44
  • @mrKorbel Do you have an active download link to the Substance L&F? can't seem to find any online. – Jide Kolade Nov 30 '12 at 13:25
  • @Jide Kolade [here is official page](http://shemnon.com/speling/2011/04/insubstantial-62-release.html) – mKorbel Nov 30 '12 at 16:36
  • @mrKorbel, Thanks guys, I have fixed the problem I had. I realized what i was doing wrong. I didn't add the Internal Frames to the JDestopPane before my call to SwingUtilities.updateComponentTreeUi(frame). Well, you can't blame a newbie like me :) – Jide Kolade Dec 03 '12 at 08:42
  • @mrKorbel, thanks for the link, I've downloaded the Substance L&F together with the Trident library but when I try to use any SubstanceL&F, i get some sorta Error In Dispatch Thread Exceptiom. How do I fix that? – Jide Kolade Dec 03 '12 at 08:45
  • @Jide Kolade [Substance is soo much EDT sensitive](http://stackoverflow.com/search?q=user%3A714968+substance) – mKorbel Dec 03 '12 at 08:52