Look and Feel - Java

0

I have my JFrame (called frmMenuPrincipal containing a JMenuBar with options) that I have put in the main the following code so that it has a good design:

try {
            UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
        } catch (Throwable e) {
            e.printStackTrace();
        }

This is the design that is shown when I execute it:

Then I created a window JInternalFrame that in the main I put the following code:

try {
            UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsClassicLookAndFeel");
        } catch (Throwable e) {
            e.printStackTrace();
        }

This is the design when I visualize it:

When I see the JInternalFrame it appears with the WindowsClassic design but when I run the JFrame, the Main Menu appears with the windows design (that's fine) but when I click on the JMenuBar options it opens the JInternalFrame with the Windows design and not windowsclassic design. How would you make each window when it will appear with its own design that was placed.

    
asked by Leandro 09.03.2017 в 17:12
source

1 answer

0

Bad news and good news ...

The bad: the UIManager places the look and feel in a singleton and only has space for a look and feel (which means you can not have two look and feels at the same time).

The good news: you can intersperse look and feel to simulate that you have two ... use the same codes you use (the UIManager.setLookAndFeel (...)), but you have to add this SwingUtilities.updateComponentTreeUI(referenciaATuFrame); to apply the look and feel in time of execution to the frame you need (obviously, you have to run the setLookAndFeel every time you change the window).

Good thing you do not need to have two look and feels in the same frame (for example, for two different panels) because there you would have to go overwrite (override) per individual component JComponent.setUI(); and that is more complex for results you need.

    
answered by 09.03.2017 в 23:00