Results 1 to 1 of 1
  1. #1
    trishtren is offline Member
    Join Date
    Feb 2011
    Posts
    53
    Rep Power
    0

    Default override the menu items

    Hey, iv been looking for a way to override the jmenu items so i can give it a custom look using java 2d, however i want to keep the standard methods such as the mouse over event that awt/swing uses but cannot seem to override in the same way i have been doing with a jpanel and jbutton to keep the standard functionality but a custom look. Any advice on how i can add text to it and display like a regular jmenu item on the menu would be good :)
    :
    Java Code:
    public class MenuText  extends JMenu  
    {
    	private Color fontcol = new Color(80, 80, 80);
    	private static Font sanSerifFont = new Font("SanSerif", Font.PLAIN, 12);
    	String buttontext;
    	/**
    	 * 
    	 */
    	private static final long serialVersionUID = 1L;
    
    	//constructor
    	public MenuText(String text)
    	{
    		buttontext = text;
    		//colour of panels
    	}
    	 @Override public void paintComponent(Graphics g)
    		{   //parent paints the background
    			super.paintComponent(g);
    			Graphics2D g2d = (Graphics2D)g;
    		    g2d.setFont(sanSerifFont);
    		    g2d.drawString(buttontext, 10,10);			
    		}
    }
    Java Code:
    // harness class
    
    public class MenuBar extends JMenuBar 
    {
    	//fields
    	private static final long serialVersionUID = 1L;
    
    	private Color background2 = new Color(80, 80, 80);
    
    	  JMenu fileMenu = new JMenu("File");
    	  VeilMenuText newitem = new VeilMenuText("Edit");
    	 
    	
    	//constructor
    	public MenuBar()
    	{
    		//colour of panels
    	 setPreferredSize(new Dimension(0,20));
    	 this.add(fileMenu);
    	 this.add(newitem);
    	 drawfilemenu();
    	}
     
     @Override public void paintComponent(Graphics g)
    	{   //parent paints the background
    		super.paintComponent(g);
    		Graphics2D g2d = (Graphics2D)g;
    		int w = getWidth();
    		int h = getHeight();
    		g2d.fillRect(0,0,w,h);
    	}
    So any help on how this class should be constructed so i can add custom text to the menu item and have it behave like the standard jmenu item however with a custom look when mouse over (i assume thats a mouse over mouse listener) would be good. This code above when added to a jmenubar for some reason does absoultely nothing but seems to override all other widgets in my frame.
    Last edited by trishtren; 05-20-2011 at 11:53 AM.

Similar Threads

  1. Struts menu items delay
    By seol_sensei in forum JavaServer Faces (JSF)
    Replies: 1
    Last Post: 05-31-2011, 01:20 AM
  2. ActionListener for Menu Items
    By CuddlyKittens11 in forum AWT / Swing
    Replies: 7
    Last Post: 04-22-2011, 06:10 AM
  3. folder/file menu items
    By jhughes in forum Advanced Java
    Replies: 2
    Last Post: 07-21-2009, 10:57 PM
  4. How to remove Eclipse context menu items?
    By Neil_ in forum Eclipse
    Replies: 0
    Last Post: 04-06-2009, 05:09 AM
  5. hyperlinks from menu items?
    By asterope118 in forum New To Java
    Replies: 1
    Last Post: 07-16-2007, 01:49 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •