关于JPanel的小问题!在JPanel里面放张图片!

青稞梅子酒 2011-04-11 02:26:17
在JPanel里面放张图片!图片和JPanel的边缘总有间隙,怎么让它没有间隙啊!
自己查了查API文档也没找到,求高手帮忙!

说明:这是图片!JPanel的背景设成了黑色!JPanel也没有设置大小!


http://zhidao.baidu.com/question/250962220.html

...全文
138 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
sasamao 2011-04-11
  • 打赏
  • 举报
回复
import java.awt.Rectangle;

import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;


public class Image extends JFrame {
JPanel jpanel;
JLabel label;
ImageIcon icon;
public Image(){
icon = new ImageIcon("pond.png");
label = new JLabel(icon);
label.setLayout(null);
label.setBounds(0,0,icon.getIconWidth(),icon.getIconHeight());

jpanel = new JPanel();
jpanel.setLayout(null);
jpanel.setBackground(Color.GRAY);
jpanel.add(label);
jpanel.setBounds(0,0,icon.getIconWidth(),icon.getIconHeight());

this.setTitle("test");
this.add(jpanel);
this.setVisible(true);
this.pack();
this.setBounds(new Rectangle(10,10,icon.getIconWidth(),icon.getIconHeight()));
this.setLocationRelativeTo(null);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public static void main(String [] args){
new Image();
}

}
主要是紅色部份的設置
青稞梅子酒 2011-04-11
  • 打赏
  • 举报
回复
图片挂了,大家打开上面的链接看吧!

62,615

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧