return new CustomPopupMenuUI();
}
public Popup getPopup
(JPopupMenu popup,
int x,
int y
) {
Popup pp = super.getPopup(popup,x,y);
panel.setBorder(new ShadowBorder(3,3));
panel.setOpaque(false);
return pp;
}
}
int xoff, yoff;
public ShadowBorder(int x, int y) {
this.xoff = x;
this.yoff = y;
insets
= new Insets(0,
0,xoff,yoff
);
}
return insets;
}
int x, int y, int width, int height) {
g.translate(x,y);
// draw right side
g.fillRect(width-xoff, yoff, xoff, height-yoff);
// draw bottom side
g.fillRect(xoff, height-yoff, width-xoff, yoff);
g.translate(-x,-y);
}
}
public class MenuTest {
UIManager.
put("PopupMenuUI",
"CustomPopupMenuUI");
frame.setJMenuBar(mb);
mb.add(menu);
menu
= new JMenu("Edit");
mb.add(menu);
frame.
getContentPane().
add("North",
new JButton("Button"));
frame.
getContentPane().
add("Center",
new JLabel("a label"));
frame.
getContentPane().
add("South",
new JCheckBox("checkbox"));
frame.pack();
frame.setSize(200,150);
frame.show();
}
}
//源代码片段来自云代码http://yuncode.net