Java 排除某些Jmenu';来自Synth的s
我在一个XML文件中使用Synth L&F,到目前为止我设置了所有内容,但是没有,我有一个嵌套的JMenu,我不希望嵌套的JMenu采用顶级JMenu的样式Java 排除某些Jmenu';来自Synth的s,java,swing,jmenu,jmenuitem,synth,Java,Swing,Jmenu,Jmenuitem,Synth,我在一个XML文件中使用Synth L&F,到目前为止我设置了所有内容,但是没有,我有一个嵌套的JMenu,我不希望嵌套的JMenu采用顶级JMenu的样式 JMenu accountMenu = new JMenu("Manage Account"); JMenuItem editUsername = new JMenuItem("Change Username"); JMenuItem editPassword = new JMenuItem("Change Pass
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);
这只是从我的代码中提取并编辑以适应,并不代表实际的代码
这就是我正在使用的SynthXML片段
<!-- ================================= -->
<!-- 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
为了更清楚,请参见图片:
文件是JMenu和Manage帐户。现在Account菜单采用了File菜单的样式,但这不起作用,因为它们有不同的背景图像
谢谢你的意思是什么
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);
}
}
从文件中
<?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>
你的意思是
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);
}
}
从文件中
<?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>
谢谢,但不完全是这样,我明白了,但现在发生的是,您应该在该JMenu上附加另一个JMenu。现在看到我的图片了。我看到了一些不想要的东西,嗯,问题是为什么要使用这个L&F请检查,有大量的替代品,有很好的Bug历史和真正的支持,我尝试了Synth,但对任何东西都不满意很多作品…也许我很懒,当然我懒散,有问题:-)谢谢,但是我确实有使用synth的理由,所以你可能知道我要做什么吗?谢谢,我管理过,我在任何情况下都使用了JPopupMenu(我想)的XML属性谢谢,但不完全是这样,我明白了,但是现在发生的事情是,你应该将另一个JMenu附加到那个JMenu上。现在看到我的图片了。我看到了一些不想要的东西,嗯,问题是为什么要使用这个L&F请检查,有大量的替代品,有很好的Bug历史和真正的支持,我尝试了Synth,但对任何东西都不满意很多作品…也许我很懒,当然我懒散,有问题:-)谢谢,但是我确实有使用synth的理由,所以你可能知道我要做什么吗?谢谢,我设法做到了,我在任何情况下都使用了JPopupMenu(我想)的XML属性谢谢