学习总结9
1:今天做事件處理,發現在JMenu上面加監聽,處理不行,只有在JMenuItem上面加監聽處理才可以!!!就在這個簡單的問題上面糾纏了好長時間。還是得注意細細節啊!!!! (注:JMenu可以加監聽,以前總結是有錯誤的!!)
?
2:給JFrame添加背景圖片:
ImageIcon img = new ImageIcon("XX.jpg");
JLabel imgLabel = new JLabel(img);
frame.getLayeredPane().add(imgLabel, new Integer(Integer.MIN_VALUE));
imgLabel.setBounds(0,0,img.getIconWidth(), img.getIconHeight());((JPanel)getContentPane()).setOpaque(false);?
?
要在JFrame上添加背景圖片,常見做法是加在layeredPane上面,并將contentPane設置成透明的即可。
?
public void setBack() {
?? ((JPanel) this.getContentPane()).setOpaque(false);
?? // Winter.jpg這個圖片的位置要跟當前這個類是同一個包下
?? URL url = Test.class.getResource("Winter.jpg");
?? ImageIcon img = new ImageIcon(url);
?? JLabel background = new JLabel(img);
?? this.getLayeredPane().add(background, new Integer(Integer.MIN_VALUE));
?? background.setBounds(0, 0, img.getIconWidth(), img.getIconHeight());
} ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?這個封裝成方法寫的不錯,拷貝下來以后直接用!!!!
轉載于:https://www.cnblogs.com/cshhs/articles/3109339.html
總結
- 上一篇: java拾遗录(一)
- 下一篇: WPF Binding