package GUI;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();
}
}-------------------------------------------------------------------------------------------------
高手求解   为什么运行会出错

解决方案 »

  1.   

    我用的是JEE  难道和Java谔谔有关?
      

  2.   

    运行下面句显示这些错误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
    at javax.swing.UIDefaults.getUIError(Unknown Source)
    at javax.swing.MultiUIDefaults.getUIError(Unknown Source)
    at javax.swing.UIDefaults.getUI(Unknown Source)
    at javax.swing.UIManager.getUI(Unknown Source)
    at javax.swing.JPopupMenu.updateUI(Unknown Source)
    at javax.swing.JPopupMenu.<init>(Unknown Source)
    at javax.swing.JPopupMenu.<init>(Unknown Source)
    at javax.swing.JMenu.ensurePopupMenuCreated(Unknown Source)
    at javax.swing.JMenu.add(Unknown Source)
    at GUI.UserInterface.<init>(UserInterface.java:34)
    at Main.MainRun.main(MainRun.java:7)
    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
    at javax.swing.UIDefaults.getUIError(Unknown Source)
    at javax.swing.MultiUIDefaults.getUIError(Unknown Source)
    at javax.swing.UIDefaults.getUI(Unknown Source)
    at javax.swing.UIManager.getUI(Unknown Source)
    at javax.swing.JPopupMenu.updateUI(Unknown Source)
    at javax.swing.JPopupMenu.<init>(Unknown Source)
    at javax.swing.JPopupMenu.<init>(Unknown Source)
    at javax.swing.JMenu.ensurePopupMenuCreated(Unknown Source)
    at javax.swing.JMenu.add(Unknown Source)
    at GUI.UserInterface.<init>(UserInterface.java:41)
    at Main.MainRun.main(MainRun.java:7)
    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
    at javax.swing.UIDefaults.getUIError(Unknown Source)
    at javax.swing.MultiUIDefaults.getUIError(Unknown Source)
    at javax.swing.UIDefaults.getUI(Unknown Source)
    at javax.swing.UIManager.getUI(Unknown Source)
    at javax.swing.JPopupMenu.updateUI(Unknown Source)
    at javax.swing.JPopupMenu.<init>(Unknown Source)
    at javax.swing.JPopupMenu.<init>(Unknown Source)
    at javax.swing.JMenu.ensurePopupMenuCreated(Unknown Source)
    at javax.swing.JMenu.add(Unknown Source)
    at GUI.UserInterface.<init>(UserInterface.java:48)
    at Main.MainRun.main(MainRun.java:7)
    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
    at javax.swing.UIDefaults.getUIError(Unknown Source)
    at javax.swing.MultiUIDefaults.getUIError(Unknown Source)
    at javax.swing.UIDefaults.getUI(Unknown Source)
    at javax.swing.UIManager.getUI(Unknown Source)
    at javax.swing.JPopupMenu.updateUI(Unknown Source)
    at javax.swing.JPopupMenu.<init>(Unknown Source)
    at javax.swing.JPopupMenu.<init>(Unknown Source)
    at javax.swing.JMenu.ensurePopupMenuCreated(Unknown Source)
    at javax.swing.JMenu.add(Unknown Source)
    at GUI.UserInterface.<init>(UserInterface.java:53)
    at Main.MainRun.main(MainRun.java:7)