2011-12-01 102 views
2

我在一個XML文件中使用了Synth L & F,我設置了所有東西,但沒有嵌套的JMenu,而且我也不想嵌套的JMenu的樣式頂級JMenu的。從Synth中排除某些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); 

這只是從我的代碼中取出並編輯以適應,並不代表實際的代碼。

那麼這是Synth的XML片斷我我使用。

<!-- ================================= --> 
<!-- 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對象以及管理帳戶。所以,現在的帳戶菜單採用文件菜單的風格,而不能工作,因爲他們有不同的背景圖片。

感謝

回答

2

你的意思???

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> 
+0

謝謝,但不完全是,我得到的,但現在情況是,你應該附加其他JMenu對象到JMenu的。查看現在包含我的圖片。 – Theron084

+0

我看到那裏有一些不想要的東西,嗯問題爲什麼使用這個L&F請檢查http://stackoverflow.com/questions/3954616/look-and-feel-in-java,有很多的替代品與偉大的錯誤歷史記錄和真正的支持,我想合成器,但並不滿足任何大量的作品......,也許我懶,相信我lazyness周圍,有問題:-) – mKorbel

+0

謝謝,但我有我的理由使用合成器,所以你可能對我要做什麼有所瞭解嗎? – Theron084