怎么把图片放进JPanel组件中。要求图片的大小跟JPanel容器的大小一样!!! 30

packagesam.util;importjava.awt.BorderLayout;publicclassInfo_dialogextendsJDialog{/***... package sam.util;

import java.awt.BorderLayout;

public class Info_dialog extends JDialog {

/**
* 详细信息面板Info_dialog
*/
private static final long serialVersionUID = -700412927658366251L;
private final JPanel contentPanel = new JPanel();
private JTextField Type_Text; //类型
private JTextField UserName_Text; // 用户名
private JTextField Ca_Text; // 卡号
private JTextField Time_text; // 时间
@SuppressWarnings("unused")
private JPanel Pic_panel;
private Icon icon;
public Info_dialog() throws MalformedURLException {
setIconImage(new ImageIcon("img/menjin.png").getImage());//窗体默认图标
setTitle("\u8BE6\u7EC6\u4FE1\u606F");
setBounds(100, 100, 554, 500);
getContentPane().setLayout(new BorderLayout());
contentPanel.setBackground(Color.WHITE);
contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
getContentPane().add(contentPanel, BorderLayout.CENTER);
contentPanel.setLayout(null);
// 详细信息面板
JPanel panel = new JPanel();
panel.setBorder(BorderFactory.createTitledBorder("详细信息"));
panel.setBackground(Color.WHITE);
panel.setBounds(10, 10, 528, 84);
contentPanel.add(panel);
panel.setLayout(null);

JLabel Type = new JLabel("\u7C7B \u578B\uFF1A");
Type.setBounds(29, 56, 54, 15);
panel.add(Type);

JLabel UserName = new JLabel("\u7528\u6237\u540D\uFF1A");
UserName.setBounds(29, 25, 54, 15);
panel.add(UserName);

JLabel Cano = new JLabel("\u5361 \u53F7\uFF1A");
Cano.setBounds(255, 25, 54, 15);
panel.add(Cano);

Ca_Text = new JTextField();
Ca_Text.setEnabled(false);
Ca_Text.setColumns(10);
Ca_Text.setBounds(319, 22, 135, 21);
panel.add(Ca_Text);

Time_text = new JTextField();
Time_text.setEnabled(false);
Time_text.setColumns(10);
Time_text.setBounds(319, 53, 135, 21);
panel.add(Time_text);

Type_Text = new JTextField();
Type_Text.setEnabled(false);
Type_Text.setColumns(10);
Type_Text.setBounds(93, 53, 135, 21);

UserName_Text = new JTextField();
UserName_Text.setEnabled(false);
UserName_Text.setColumns(10);
UserName_Text.setBounds(93, 22, 135, 21);
panel.add(UserName_Text);

panel.add(Type_Text);
JLabel Time = new JLabel("\u65F6 \u95F4\uFF1A");
Time.setBounds(255, 56, 54, 15);
panel.add(Time);
// 图片信息面板
JPanel Pic_panel = new JPanel();
Pic_panel.setBackground(new Color(255, 255, 255));
Pic_panel.setBorder(BorderFactory.createTitledBorder("图片信息"));
Pic_panel.setBounds(279, 104, 259, 352);
contentPanel.add(Pic_panel);

}

public void Dialog_Info(Object cano, Object time, Object type,
Object username, Object pictureName) {
Ca_Text.setText((String) cano);
Time_text.setText((String) time);
Type_Text.setText((String) type);
UserName_Text.setText((String) username);

}

}
展开
 我来答
知道才说呢
2012-03-23 · 超过16用户采纳过TA的回答
知道答主
回答量:37
采纳率:0%
帮助的人:37.8万
展开全部
JPanel panel = new JPanel() {
protected void paintComponent(Graphics g) {
ImageIcon icon = new ImageIcon(imgPath);
g.drawImage(icon.getImage(), 0, 0, getWidth(),getHeight(),
icon.getImageObserver());
}
};
new panel的时候会自动调用
protected void paintComponent(),然后自己用drawImage()画上你的图片
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式