0
我试图从框架的左侧创建一个菜单滑块。 它需要被浮置的内容,其中,i可以用鼠标监听器(打开菜单当鼠标接近左边缘)总是访问它的上方。如何在JFrame中设置glasspane的位置?
好了,我把我的玻璃面板(我的JPanel)为setOpaue(假的),它是浮在上面的内容。 但玻璃窗总是位于中心,我需要有可能移动它,滑动它,但没有运气。
定义的setBounds和setLocation不会为我工作。
任何一个可以请帮我这个?代码的
部分:
public class MYFrame extends JFrame {
public MYFrame(){
this.setLayout(new BorderLayout());
this.add(panel1,BorderLayout.NORTH);
this.add(panel2,BorderLayout.CENTER);
this.add(panel3,BorderLayout.EAST);
this.getRootPane().setGlassPane(new MyGlass());
this.getRootPane().getGlassPane().setVisible(true);
this.setVisible(true);
}
public class MyGlass extends JPanel{
ImageIcon imageIcon = new ImageIcon("BG.png");
JLabel label = new JLabel(imageIcon);
public MyGlass(){
this.add(label);
this.setOpaque(false);
this.pack();
this.setVisible(true);
}
}
}
首先,感谢您详细的解答。但我想用里面的按钮创建一个真正的菜单。我不知道我可以如何paintComponent(g)的按钮。 – 2015-02-23 17:24:55
你是什么意思?你只需要添加按钮'MenuPane'和管理他们像往常一样... – 2015-02-23 20:28:06
的MenuPane只是一个JPanel,我做到了透明的为了证明这一点,你不需要的paintComponent方法(或者应该改变不透明状态) – MadProgrammer 2015-02-23 20:36:03