Topic: 怎样才能给面板加背景图片

  Print this page

1.怎样才能给面板加背景图片 Copy to clipboard
Posted by: helloworld84
Posted on: 2004-07-18 11:28

求大侠帮忙,怎样给面板加背景图片?

2.Re:怎样才能给面板加背景图片 [Re: helloworld84] Copy to clipboard
Posted by: caike
Posted on: 2004-07-18 15:14

设置layout
panel.setLayout(null);

//加入背景图
panel.add(image);

//再加入其他组件,如JButton,JLabel
panel.add(button);

//得到panel的大小
Insets insets = panel.getInsets();

//设置加入到panel的button的位置,是相对于panel的
(X,Y,width,heigh)

button.setBounds(insets.left+250, 150 + insets.top,
25, 25);

3.Re:怎样才能给面板加背景图片 [Re: helloworld84] Copy to clipboard
Posted by: sxhv998
Posted on: 2004-07-21 14:38

我没试过上面仁兄的方法!
我只知道可以重载panel的paintComponent(Graphics g)方法

在这个方法中画这个图片
如:

public void paintComponent(Graphics g) {
g.drawImage(image,0,0,this);
}


   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923