import java.awt.AlphaComposite;
import java.awt.Color;
import java.awt.Component;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Insets;
import java.awt.image.BufferedImage;import javax.swing.JComponent;
import javax.swing.JPanel;
import javax.swing.JPopupMenu;
import javax.swing.Popup;
import javax.swing.border.AbstractBorder;
import javax.swing.plaf.ComponentUI;
import javax.swing.plaf.basic.BasicPopupMenuUI;public class CustomPopupMenuUI extends BasicPopupMenuUI{
public static ComponentUI createUI(JComponent c){
return new CustomPopupMenuUI();
}
public Popup getPopup(JPopupMenu popup,int x,int y){
Popup pp=super.getPopup(popup, x, y);
JPanel panel=(JPanel)popup.getParent();
panel.setBorder(new ShadowBorder(3,3));
panel.setOpaque(false);
return pp;
}
}
class ShadowBorder extends AbstractBorder{
int xoff,yoff;
Insets insets;
public ShadowBorder(int x,int y){
this.xoff=x;
this.yoff=y;
insets=new Insets(0,0,xoff,yoff);
}
public Insets getBorderInsets(Component c){
return insets;
}
public void paintBorder(Component comp,Graphics g,
int x,int y,int width,int height){
g.setColor(Color.BLACK);
g.translate(x, y);
g.fillRect(width-xoff, yoff, xoff, height-yoff);
g.fillRect(xoff, height-yoff, width-xoff, yoff);
g.translate(-x, -y);
}
}
-------------------------------------------------------------------------------------------
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.UIManager;public class UserInterface {
public UserInterface(){UIManager.put("PopupMenuUI","CustomPopupMenuUI");JFrame frame=new JFrame();
JMenuBar mb=new JMenuBar();
frame.setJMenuBar(mb);
JMenu menu=new JMenu("File");
mb.add(menu);
menu.add(new JMenuItem("Open"));
menu.add(new JMenuItem("Save"));
menu.add(new JMenuItem("Close"));
menu.add(new JMenuItem("Exit"));frame.pack();
frame.setSize(800,600);
frame.show();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public static void main(String[] args) {
UserInterface user=new UserInterface();
}
}-------------------------------------------------------------------------------------------------
高手求解 为什么运行会出错
它会列出一大堆问题
UIDefaults.getUI() failed: no ComponentUI class for: javax.swing.JPopupMenu[,0,0,0x0,invalid,alignmentX=0.0,alignmentY=0.0,border=,flags=0,maximumSize=,minimumSize=,preferredSize=,desiredLocationX=0,desiredLocationY=0,label=,lightWeightPopupEnabled=true,margin=,paintBorder=true]
java.lang.Error

解决方案 »

  1.   


    import javax.swing.JFrame;
    import javax.swing.JMenu;
    import javax.swing.JMenuBar;
    import javax.swing.JMenuItem;
    import javax.swing.UIManager;public class UserInterface {
    public UserInterface() { String popUI = CustomPopupMenuUI.class.getName();
    UIManager.put("PopupMenuUI", popUI); JFrame frame = new JFrame();
    JMenuBar mb = new JMenuBar();
    frame.setJMenuBar(mb);
    JMenu menu = new JMenu("File");
    mb.add(menu);
    menu.add(new JMenuItem("Open"));
    menu.add(new JMenuItem("Save"));
    menu.add(new JMenuItem("Close"));
    menu.add(new JMenuItem("Exit")); frame.pack();
    frame.setSize(800, 600);
    frame.show();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    } public static void main(String[] args) {
    UserInterface user = new UserInterface();
    }
    }
      

  2.   


    高手  求解为什么那里出错  我记得老师说过eclipse里面调jdk  说不然以后某些程序可能用不了
    请问你知道如何调吗   那个我忘记了