@huxiweng,重绘按钮啊,panel都可以,这个没搞出来,这个不搞出来,主题风格就很不协调了

解决方案 »

  1.   


    你先把你实现那部分代码发一下

    这是在桌面显示的一个动态label右键是这样的,可以看到后面有图片显示,但是被JMenuItem的背景挡住了,而且JMenuItem的背景也没搞好这是代码
    String ico = "UI\\BKIMG.png";

    JFrame mini = new JFrame();
    MyPanel rootp = new MyPanel();
    JLabel beaut = new JLabel(new ImageIcon("UI\\25368_1.gif"));
    Point p1_p = new Point(0,0); //用于窗口拖拽
    MyPopmenu popm = new MyPopmenu(ico);
    MyMenuItem mainp = new MyMenuItem();
    JMenuItem restart = new JMenuItem("重启");
    JMenuItem dstroy = new JMenuItem("注销");
    JMenuItem colse = new JMenuItem("关机");
    JMenuItem exit = new JMenuItem("退出");
    public void wininit(){

    mainp.setStr("张雄"); mainp.setBackImg2("UI\\miniTextA.png"); popm.setPopupSize(55, 225); popm.setBorderPainted(false); popm.add(mainp);
    popm.addSeparator();
    popm.add(restart);popm.addSeparator();
    popm.add(dstroy);popm.addSeparator();
    popm.add(colse);popm.addSeparator();
    popm.add(exit);

    rootp.setLayout(null);
    rootp.addMouseListener(this);
    rootp.addMouseMotionListener(this);
    rootp.setSize(40, 40);

    beaut.setSize(40, 40);
    rootp.add(beaut);
    rootp.add(popm);

    mini.setContentPane(rootp);
    mini.setResizable(false);
    mini.setUndecorated(true);
    AWTUtilities.setWindowOpaque(mini, false);
    mini.setSize(400, 300);
    mini.setVisible(true);
    }下面这个是重绘popupmenu的代码
    public class MyPopmenu extends JPopupMenu{
       private Image backImg;
        
        
        public MyPopmenu(String imgPath){
         try
         {
         File f = new File(imgPath);
         backImg = ImageIO.read(f);
         }
         catch (IOException e)
         {
         e.printStackTrace();
         }
        }
        
        public MyPopmenu(){
           
        }
        public void SetDefulatSize(){
        
        }
        @Override
         public void paintComponent(Graphics g) {
             super.paintComponent(g);
             if(backImg!=null)
                 g.drawImage(backImg, 0, 0,100,50, null);
         }    public Image getBackImg() {
            return backImg;
        }    public void setBackImg(Image backImg) {
            this.backImg = backImg;
            this.repaint();
        }
        
        public void setBackImg2(String img2Path) {
         Image backImg2 = null ;
         try
         {
         File f = new File(img2Path);
         backImg2 = ImageIO.read(f);
         }
         catch (IOException e)
         {
         e.printStackTrace();
         }
            this.backImg = backImg2;
            this.repaint();
        }
    }menuitem的重绘和这个是一样的就不发了如果右键菜单直接add(“sxsxs”),好像也不行
    是想做成这个风格的
      

  2.   


    你先把你实现那部分代码发一下

    这是在桌面显示的一个动态label右键是这样的,可以看到后面有图片显示,但是被JMenuItem的背景挡住了,而且JMenuItem的背景也没搞好这是代码
    String ico = "UI\\BKIMG.png";

    JFrame mini = new JFrame();
    MyPanel rootp = new MyPanel();
    JLabel beaut = new JLabel(new ImageIcon("UI\\25368_1.gif"));
    Point p1_p = new Point(0,0); //用于窗口拖拽
    MyPopmenu popm = new MyPopmenu(ico);
    MyMenuItem mainp = new MyMenuItem();
    JMenuItem restart = new JMenuItem("重启");
    JMenuItem dstroy = new JMenuItem("注销");
    JMenuItem colse = new JMenuItem("关机");
    JMenuItem exit = new JMenuItem("退出");
    public void wininit(){

    mainp.setStr("张雄"); mainp.setBackImg2("UI\\miniTextA.png"); popm.setPopupSize(55, 225); popm.setBorderPainted(false); popm.add(mainp);
    popm.addSeparator();
    popm.add(restart);popm.addSeparator();
    popm.add(dstroy);popm.addSeparator();
    popm.add(colse);popm.addSeparator();
    popm.add(exit);

    rootp.setLayout(null);
    rootp.addMouseListener(this);
    rootp.addMouseMotionListener(this);
    rootp.setSize(40, 40);

    beaut.setSize(40, 40);
    rootp.add(beaut);
    rootp.add(popm);

    mini.setContentPane(rootp);
    mini.setResizable(false);
    mini.setUndecorated(true);
    AWTUtilities.setWindowOpaque(mini, false);
    mini.setSize(400, 300);
    mini.setVisible(true);
    }下面这个是重绘popupmenu的代码
    public class MyPopmenu extends JPopupMenu{
       private Image backImg;
        
        
        public MyPopmenu(String imgPath){
         try
         {
         File f = new File(imgPath);
         backImg = ImageIO.read(f);
         }
         catch (IOException e)
         {
         e.printStackTrace();
         }
        }
        
        public MyPopmenu(){
           
        }
        public void SetDefulatSize(){
        
        }
        @Override
         public void paintComponent(Graphics g) {
             super.paintComponent(g);
             if(backImg!=null)
                 g.drawImage(backImg, 0, 0,100,50, null);
         }    public Image getBackImg() {
            return backImg;
        }    public void setBackImg(Image backImg) {
            this.backImg = backImg;
            this.repaint();
        }
        
        public void setBackImg2(String img2Path) {
         Image backImg2 = null ;
         try
         {
         File f = new File(img2Path);
         backImg2 = ImageIO.read(f);
         }
         catch (IOException e)
         {
         e.printStackTrace();
         }
            this.backImg = backImg2;
            this.repaint();
        }
    }menuitem的重绘和这个是一样的就不发了如果右键菜单直接add(“sxsxs”),好像也不行
    是想做成这个风格的你那个右键背景图片还是重PS下。还有就是paintComponent方法里那个坐标也要调整下