custommenuitemui.java

来自「oraily的Swing hacks code」· Java 代码 · 共 29 行

JAVA
29
字号
import java.awt.*;import java.awt.image.*;import javax.swing.*;import javax.swing.plaf.*;import javax.swing.plaf.metal.*;import javax.swing.plaf.basic.*;public class CustomMenuItemUI extends BasicMenuItemUI {    public static ComponentUI createUI(JComponent c) {        return new CustomMenuItemUI();    }        public void paint(Graphics g, JComponent comp) {        // paint to the buffered image        BufferedImage bufimg = new BufferedImage(comp.getWidth(),comp.getHeight(),            BufferedImage.TYPE_INT_ARGB);        Graphics2D g2 = bufimg.createGraphics();                // restore the foreground color in case the super class needs it        g2.setColor(g.getColor());        super.paint(g2,comp);        // do an alpha composite        Graphics2D gx = (Graphics2D) g;        gx.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER,0.8f));        gx.drawImage(bufimg,0,0,null);    }    }

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?