- 论坛徽章:
- 0
|
我自定义了背景显示面板,背景图片是能够正确显示的。但是在面板上放置的toolbar却不能正常显示。需要将鼠标经过其上时,才能显示出来。问各位大神什么原因!
背景面板代码:- import java.awt.Graphics;
- import java.awt.Graphics2D;
- import java.awt.Image;
- import java.awt.Toolkit;
- import java.net.URL;
- import javax.swing.JPanel;
- /**
- *
- * @author dongbeisong
- */
- public class ImagePanel extends JPanel{
- private Image myImage;
- /**
- * Creates new form ImagePanel
- */
- public ImagePanel() {
- super();
- URL toolbarbackimage = this.getClass().getResource("/edu/upl/huiwencheck/ui/resounce/toolbarback.jpg");
- myImage = Toolkit.getDefaultToolkit().getImage(toolbarbackimage);
- this.setBounds(0, 0, 930, 70);
- }
- @Override
- public void paintComponent(Graphics g) {
- super.paintComponent(g);
- Graphics2D g2D = (Graphics2D) g;
- if (myImage != null) {// 绘制背景
- g2D.drawImage(myImage, 0, 0, this.getWidth(), this.getHeight(), this);
- }
- g2D.dispose();
- }
-
-
- }
复制代码 程序运行时:
鼠标经过后:
|
|