好像我在 Java 中发现了一个错误:
我需要创建JFrame
一个透明背景,现在我需要显示JPopupMenu
一些用户操作。当JPopupMenu
完全容纳在JFrame
. 但是当JPopupMenu
部分在 之外时JFrame
,没有项目可见。
SSCCE:
public class PopupTest {
public static void main(String[] a) {
final JFrame frame = new JFrame();
frame.setSize(500, 500);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
final JPanel panel = new JPanel(new BorderLayout());
panel.setBorder(BorderFactory.createLineBorder(Color.RED));
panel.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
if (e.getButton() == MouseEvent.BUTTON3) {
JPopupMenu menu = new JPopupMenu();
for (int i = 0 ; i < 10; i++) {
menu.add(String.valueOf(i));
}
menu.show(panel, e.getX(), e.getY());
}
}
});
frame.setContentPane(panel);
frame.setUndecorated(true);
frame.setBackground(new Color(50, 50, 50, 200));
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
frame.setVisible(true);
}
});
}
}
有谁知道如何解决这个问题?
PS: JDK 7u40,Win x64