1

I am using Synth L&F in a XML File, I set up everything so far, but no I have a nested JMenu, and I don't want the nested ones to take the style of the top JMenu's.

    JMenu accountMenu = new JMenu("Manage Account");
    JMenuItem editUsername = new JMenuItem("Change Username");
    JMenuItem editPassword = new JMenuItem("Change Password");
    accountMenu.add(editUsername);
    accountMenu.add(editPassword);
    fileMenu.add(accountMenu);

This was only taken from my code and edited to fit in, doesn't represent the actual code.

Then this is the Synth XML I snippet I am using.

<!-- ================================= -->
<!-- MENU -->
<!-- ================================= -->
<style id="MenuStyle">
    <insets top="2" bottom="2" right="10" left="7" />
    <state>
        <font name="Calibre" size="14" style="BOLD" />
        <color value="#cccccc" type="TEXT_FOREGROUND" />
    </state>

    <state value="DISABLED">
        <color value="WHITE" type="TEXT_FOREGROUND" />
    </state>

    <state value="SELECTED">
        <imagePainter method="MenuBackground" path="Bin/Images/headerbarActive.jpg"
            sourceInsets="0 0 0 0" />
        <color value="WHITE" type="TEXT_FOREGROUND" />
    </state>
</style>
<bind style="MenuStyle" type="region" key="Menu" />

<!-- ================================= -->
<!-- MENU ITEM-->
<!-- ================================= -->
<style id="MenuItemStyle">
    <insets top="3" bottom="3" right="20" left="5" />
    <state>
        <imagePainter method="MenuItemBackground" path="Bin/Images/menuItem.jpg"
            sourceInsets="0 0 0 0" />
        <font name="Calibre" size="14" style="PLAIN" />
        <color value="#cccccc" type="TEXT_FOREGROUND" />
    </state>
    <state value="MOUSE_OVER">
        <imagePainter method="MenuItemBackground" path="Bin/Images/menuItemActive.jpg"
            sourceInsets="0 0 0 0" />
        <color value="#000000" type="TEXT_FOREGROUND" />
    </state>
    <state value="DISABLED">
        <color value="WHITE" type="TEXT_FOREGROUND" />
    </state>
</style>
<bind style="MenuItemStyle" type="region" key="MenuItem" />

So now I am looking to target lets say only the AccountMenu JMenu and give it the same style as JMenuItems and not JMenus

To be more clear, please see picture:

Menu Layout http://avengerpaintball.co.za/screen01.jpg

File is a JMenu as well as Manage Account. So now the Account Menu takes the Style of File Menu, and that can't work, because they have different background Images.

Thanks

kleopatra
  • 51,061
  • 28
  • 99
  • 211
Theron084
  • 155
  • 2
  • 3
  • 11

1 Answers1

1

are you meaning ???

import javax.swing.*;
import javax.swing.plaf.synth.SynthLookAndFeel;

public class ButtonRollover extends JFrame {

    private static final long serialVersionUID = 1L;

    public ButtonRollover() {
        JMenuBar fileMenu = new JMenuBar();
        setJMenuBar(fileMenu);
        JMenu accountMenu = new JMenu("Manage Account");
        JMenuItem editUsername = new JMenuItem("Change Username");
        JMenuItem editPassword = new JMenuItem("Change Password");
        accountMenu.add(editUsername);
        accountMenu.add(editPassword);
        fileMenu.add(accountMenu);
    }

    public static void main(String[] args) {
        try {
            SynthLookAndFeel laf = new SynthLookAndFeel();
            laf.load(ButtonRollover.class.getResourceAsStream("menusynt.xml"), ButtonRollover.class);
            UIManager.setLookAndFeel(laf);
        } catch (Exception e) {
            e.printStackTrace();
        }
        ButtonRollover frame = new ButtonRollover();
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setSize(400, 200);
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);
    }
}

and from file

<?xml version="1.0" encoding="UTF-8"?>
<root>
<!-- ================================= -->
<!-- MENU menusynt.xml -->
<!-- ================================= -->
<style id="MenuStyle">
    <insets top="2" bottom="2" right="10" left="7" />
    <state>
        <font name="Calibre" size="14" style="BOLD" />
        <color value="#cccccc" type="TEXT_FOREGROUND" />
    </state>

    <state value="DISABLED">
        <color value="WHITE" type="TEXT_FOREGROUND" />
    </state>

    <state value="SELECTED">
        <!--<imagePainter method="MenuBackground" path="src/Paint/Images/failed.png"
            sourceInsets="0 0 0 0" />-->
        <color value="WHITE" type="TEXT_FOREGROUND" />
    </state>
</style>
<bind style="MenuStyle" type="region" key="Menu" />

<!-- ================================= -->
<!-- MENU ITEM-->
<!-- ================================= -->
<style id="MenuItemStyle">
    <insets top="3" bottom="3" right="20" left="5" />
    <state>
        <!-- <imagePainter method="MenuItemBackground" path="src/Paint/Images/passed.png"
            sourceInsets="0 0 0 0" />-->
        <font name="Calibre" size="14" style="PLAIN" />
        <color value="#cccccc" type="TEXT_FOREGROUND" />
    </state>
    <state value="MOUSE_OVER">
       <!--  <imagePainter method="MenuItemBackground" path="src/Paint/Images/failed.png"
            sourceInsets="0 0 0 0" />-->
        <color value="#000000" type="TEXT_FOREGROUND" />
    </state>
    <state value="DISABLED">
        <color value="WHITE" type="TEXT_FOREGROUND" />
    </state>
</style>
<bind style="MenuItemStyle" type="region" key="MenuItem" />

</root>
mKorbel
  • 109,525
  • 20
  • 134
  • 319
  • Thanks, but not exactly, I get that, but what now happens is that should you attach another JMenu to that JMenu. See My Image Included Now. – Theron084 Dec 01 '11 at 22:07
  • I see there some un-wanted whatever, hmmm question why use this L&F please to check http://stackoverflow.com/questions/3954616/look-and-feel-in-java , there are tons alternatives with with great Bug History and real support, I tried Synth, but not satisfied with anything lots of works ...., maybe I lazy, sure I lazyness around, there is problem :-) – mKorbel Dec 01 '11 at 22:22
  • Thanks, but I do have my reasons for using synth, So do you maybe have any idea about what I am to do? – Theron084 Dec 02 '11 at 12:00
  • Thanks, I managed, I used the XML Property for a JPopupMenu (I Think)Thank in any case – Theron084 Dec 02 '11 at 23:02