首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >从Synth中排除某些Jmenu

从Synth中排除某些Jmenu
EN

Stack Overflow用户
提问于 2011-12-02 05:26:30
回答 1查看 489关注 0票数 1

我在一个XML文件中使用Synth L&F,到目前为止我已经设置好了所有的东西,但是不,我有一个嵌套的JMenu,我不想让嵌套的那些采用顶级JMenu的样式。

代码语言:javascript
复制
    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);

这只取自我的代码,并进行了编辑以适应,并不代表实际的代码。

这就是我正在使用的Synth XML片段。

代码语言:javascript
复制
<!-- ================================= -->
<!-- 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" />

因此,现在我希望只针对AccountMenu JMenu,并赋予它与JMenuItems相同的风格,而不是JMenus

为了说得更清楚,请看图片:

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

文件既是一个JMenu,也是一个管理帐户。所以现在帐户菜单采用文件菜单的样式,这是不能工作的,因为它们有不同的背景图像。

谢谢

EN

回答 1

Stack Overflow用户

发布于 2011-12-02 05:56:19

你是说?

代码语言:javascript
复制
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);
    }
}

和来自文件

代码语言:javascript
复制
<?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>
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/8348524

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档