2

I'm trying to create a custom Look-And-Feel using the Synth-Framework.

I successfully used a tutorial ( Look-And-Feel Tutorial by Oracle/Sun ) to experiment,and managed to skin Buttons, Panels etc.

The problem i have now is,that i want to decorate the Window/JFrame.

I read some things about it and tried it out with the MetalLookAndFeel and this Code,that works:

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

    }
    javax.swing.JFrame.setDefaultLookAndFeelDecorated(true);
    new SFframe().setVisible(true);

Now i try to use my own LAF:

<?xml version="1.0" encoding="UTF-8"?>
<synth>    
    <!-- Style that all regions will use -->
    <style id="backingStyle">
        <opaque value="TRUE"/>
        <font name="Dialog" size="14"/>
        <state>
            <color value="#04688D" type="BACKGROUND"/>
            <color value="#FFFFFF" type="FOREGROUND"/> 
        </state>
        <defaultsProperty key="Synthetica.window.decoration" type="boolean" value="true"/>
    </style>
    <bind style="backingStyle" type="region" key=".*"/>
    <style id="button">
        <!-- Shift the text one pixel when pressed -->
        <property key="Button.textShiftOffset" type="integer" value="1"/>
        <!-- set size of buttons -->
        <insets top="4" left="4" bottom="4" right="4"/>
        <state>
            <imagePainter method="buttonBackground" path="/synth/images/Button.png" sourceInsets="4 4 4 4"/>
            <font name="Dialog" size="16"/>
            <color type="TEXT_FOREGROUND" value="#FFFFFF"/>
        </state>              
        <state value="PRESSED"> 
            <imagePainter method="buttonBackground" path="/synth/images/Button_pressed.png" sourceInsets="4 4 4 4"/>
        </state>            
        <state value="MOUSE_OVER">    
            <imagePainter method="buttonBackground" path="/synth/images/Button_over.png" sourceInsets="4 4 4 4"/>
        </state>
    </style>
    <bind style="button" type="region" key="Button"/>
</synth>

The code i use to load the LAF looks like this:

    SynthLookAndFeel laf = new SynthLookAndFeel();
    try{
        InputStream in = SFframe.class.getResourceAsStream("/synth/synth.xml");
        laf.load(in, SFframe.class);
        UIManager.setLookAndFeel(laf);
    }catch(ParseException | UnsupportedLookAndFeelException e){
        e.printStackTrace();
    }
    javax.swing.JFrame.setDefaultLookAndFeelDecorated(true);
    new SFframe().setVisible(true);

The Buttons and Panels get skinned, but of course, the Window/JFrame doesn't.

I just can't find a source on how to skin/decorate a Window/JFrame with Synth-XML. Can someone help me there?

Martin Weber
  • 3,482
  • 4
  • 18
  • 22

2 Answers2

1
  • AFAIK isn't possible to decorating JFrame/JDialog/JWindow with own L&F

  • JFrame/JDialog/JWindow is based on peers came from native OS, by default has the same decorations type color, font, font size as rest of windows invoked from Native OS

  • AFAIK Substance can do that, have look at its code source, ref. post by (-:forked new Owner:-)

Community
  • 1
  • 1
mKorbel
  • 108,320
  • 17
  • 126
  • 296
1

Well, it is possible to decorate JFrame, JDialog and even JWindow with your own L&F, but i am not sure that Synth can do that. Atleast i didn't find any information about that.

L&F like Substance, Synthetica and others use a small cheat to decorate JFrame and JDialog - when setDefaultLookAndFeelDecorated is set to true JRootPane UI disables native frame/dialog decoration and simply displays its own styling. Also some native features like non-opaque frames/dialogs are very handy in that case and makes you feel that window is actually decorated with a different style (you cannot create a good window shade effect without those features).

Mikle Garin
  • 9,824
  • 34
  • 58
  • and those attempts don't [work in Java7 by default](http://stackoverflow.com/questions/16219111/cant-transparent-and-undecorated-jframe-in-jdk7-when-enabling-nimbus) – mKorbel May 14 '13 at 11:06
  • Yep, for some reason Java developers disabled this feature for decorated frames and dialogs in Java 7 and later (which is pretty dumb imo). That could be easily confirmed by looking into `java.awt.Dialog` or `java.awt.Frame` `setOpacity(float opacity)` method source in JDK 7 and later. – Mikle Garin May 14 '13 at 13:15