java GUI 怎么取消边框 设置窗口左上角的图片 设置背景图片
5个回答
展开全部
import java.awt.Image;
import java.awt.Rectangle;
import java.awt.TextArea;
import java.awt.Toolkit;
import javax.swing.*;
public class BgImage extends JFrame {
// 定义图片
private ImageIcon bgImg = new ImageIcon(this.getClass().getResource(
"/1.jpg"));// 图片路径不要写错了
private JPanel mainJPanel = null;
private JPanel centerJPanel = null;
private JLabel imgLabel = new JLabel(bgImg);
// 构造方法
public BgImage() {
initialize();
}
private void initialize() {
/*
* 自定义图形左上角的图片
*/
Toolkit tk = Toolkit.getDefaultToolkit();
Image i = tk.getImage(this.getClass().getResource("/leave.jpg"));
this.setIconImage(i);
/*
* 取消窗口的边框
*/
this.setUndecorated(true);
this.getRootPane().setWindowDecorationStyle(0);
this.setSize(640, 800);
this.setResizable(false);//右上角的变大按钮失效
this.add(getcenterJpanel());
// 把图片设为JFrame背景
this.getLayeredPane().add(imgLabel, new Integer(Integer.MIN_VALUE));
imgLabel.setBounds(0, 0, bgImg.getIconWidth(), bgImg.getIconHeight());
((JPanel) getContentPane()).setOpaque(false); // 将JFrame上自带的面板设置为透明,否则背景图片不会显示出来
setSize(bgImg.getIconWidth() + 5, bgImg.getIconHeight() + 35);
this.setLocationRelativeTo(null);
}
/**
* 得到主面板
*
*/
public JPanel getcenterJpanel() {
if (mainJPanel == null) {
mainJPanel = new JPanel();
mainJPanel.setOpaque(false);// 设置为透明
JLabel passWord = new JLabel("您的密码");
JPasswordField jt = new JPasswordField(8);
jt.setOpaque(false);
mainJPanel.add(passWord);
mainJPanel.add(jt);
}
return mainJPanel;
}
public static void main(String[] args) {
new BgImage().setVisible(true);
}
}
import java.awt.Rectangle;
import java.awt.TextArea;
import java.awt.Toolkit;
import javax.swing.*;
public class BgImage extends JFrame {
// 定义图片
private ImageIcon bgImg = new ImageIcon(this.getClass().getResource(
"/1.jpg"));// 图片路径不要写错了
private JPanel mainJPanel = null;
private JPanel centerJPanel = null;
private JLabel imgLabel = new JLabel(bgImg);
// 构造方法
public BgImage() {
initialize();
}
private void initialize() {
/*
* 自定义图形左上角的图片
*/
Toolkit tk = Toolkit.getDefaultToolkit();
Image i = tk.getImage(this.getClass().getResource("/leave.jpg"));
this.setIconImage(i);
/*
* 取消窗口的边框
*/
this.setUndecorated(true);
this.getRootPane().setWindowDecorationStyle(0);
this.setSize(640, 800);
this.setResizable(false);//右上角的变大按钮失效
this.add(getcenterJpanel());
// 把图片设为JFrame背景
this.getLayeredPane().add(imgLabel, new Integer(Integer.MIN_VALUE));
imgLabel.setBounds(0, 0, bgImg.getIconWidth(), bgImg.getIconHeight());
((JPanel) getContentPane()).setOpaque(false); // 将JFrame上自带的面板设置为透明,否则背景图片不会显示出来
setSize(bgImg.getIconWidth() + 5, bgImg.getIconHeight() + 35);
this.setLocationRelativeTo(null);
}
/**
* 得到主面板
*
*/
public JPanel getcenterJpanel() {
if (mainJPanel == null) {
mainJPanel = new JPanel();
mainJPanel.setOpaque(false);// 设置为透明
JLabel passWord = new JLabel("您的密码");
JPasswordField jt = new JPasswordField(8);
jt.setOpaque(false);
mainJPanel.add(passWord);
mainJPanel.add(jt);
}
return mainJPanel;
}
public static void main(String[] args) {
new BgImage().setVisible(true);
}
}
2013-07-21
展开全部
import java.awt.Image;
import java.awt.Rectangle;
import java.awt.TextArea;
import java.awt.Toolkit;import javax.swing.*;public class BgImage extends JFrame {
// 定义图片
private ImageIcon bgImg = new ImageIcon(this.getClass().getResource(
"/1.jpg"));// 图片路径不要写错了 private JPanel mainJPanel = null; private JPanel centerJPanel = null; private JLabel imgLabel = new JLabel(bgImg); // 构造方法
public BgImage() {
initialize(); } private void initialize() { /*
* 自定义图形左上角的图片
*/
Toolkit tk = Toolkit.getDefaultToolkit();
Image i = tk.getImage(this.getClass().getResource("/leave.jpg"));
this.setIconImage(i);
/*
* 取消窗口的边框
*/
this.setUndecorated(true);
this.getRootPane().setWindowDecorationStyle(0); this.setSize(640, 800);
this.setResizable(false);//右上角的变大按钮失效 this.add(getcenterJpanel()); // 把图片设为JFrame背景
this.getLayeredPane().add(imgLabel, new Integer(Integer.MIN_VALUE)); imgLabel.setBounds(0, 0, bgImg.getIconWidth(), bgImg.getIconHeight()); ((JPanel) getContentPane()).setOpaque(false); // 将JFrame上自带的面板设置为透明,否则背景图片不会显示出来 setSize(bgImg.getIconWidth() + 5, bgImg.getIconHeight() + 35); this.setLocationRelativeTo(null);
} /**
* 得到主面板
*
*/
public JPanel getcenterJpanel() {
if (mainJPanel == null) {
mainJPanel = new JPanel();
mainJPanel.setOpaque(false);// 设置为透明
JLabel passWord = new JLabel("您的密码");
JPasswordField jt = new JPasswordField(8);
jt.setOpaque(false);
mainJPanel.add(passWord);
mainJPanel.add(jt); } return mainJPanel;
} public static void main(String[] args) {
new BgImage().setVisible(true);
}}
import java.awt.Rectangle;
import java.awt.TextArea;
import java.awt.Toolkit;import javax.swing.*;public class BgImage extends JFrame {
// 定义图片
private ImageIcon bgImg = new ImageIcon(this.getClass().getResource(
"/1.jpg"));// 图片路径不要写错了 private JPanel mainJPanel = null; private JPanel centerJPanel = null; private JLabel imgLabel = new JLabel(bgImg); // 构造方法
public BgImage() {
initialize(); } private void initialize() { /*
* 自定义图形左上角的图片
*/
Toolkit tk = Toolkit.getDefaultToolkit();
Image i = tk.getImage(this.getClass().getResource("/leave.jpg"));
this.setIconImage(i);
/*
* 取消窗口的边框
*/
this.setUndecorated(true);
this.getRootPane().setWindowDecorationStyle(0); this.setSize(640, 800);
this.setResizable(false);//右上角的变大按钮失效 this.add(getcenterJpanel()); // 把图片设为JFrame背景
this.getLayeredPane().add(imgLabel, new Integer(Integer.MIN_VALUE)); imgLabel.setBounds(0, 0, bgImg.getIconWidth(), bgImg.getIconHeight()); ((JPanel) getContentPane()).setOpaque(false); // 将JFrame上自带的面板设置为透明,否则背景图片不会显示出来 setSize(bgImg.getIconWidth() + 5, bgImg.getIconHeight() + 35); this.setLocationRelativeTo(null);
} /**
* 得到主面板
*
*/
public JPanel getcenterJpanel() {
if (mainJPanel == null) {
mainJPanel = new JPanel();
mainJPanel.setOpaque(false);// 设置为透明
JLabel passWord = new JLabel("您的密码");
JPasswordField jt = new JPasswordField(8);
jt.setOpaque(false);
mainJPanel.add(passWord);
mainJPanel.add(jt); } return mainJPanel;
} public static void main(String[] args) {
new BgImage().setVisible(true);
}}
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
取消边框的话,把继承jframe改成继承jwindow对象好像就可以了,背景的话,
好像可以用这种
JPanel p = new JPanel() {
private static final long serialVersionUID = 1L;
@Override
protected void paintComponent(Graphics g) {
try {
BufferedImage img = ImageIO.read(new File(this.getClass().getResource("1.jpg").getPath()));
g.drawImage(img, 0, 0, this.getWidth(), this.getHeight(), null);
} catch (IOException e) {
e.printStackTrace();
}
}
};
左上角的图片好像是setIcon方法设置的
好像可以用这种
JPanel p = new JPanel() {
private static final long serialVersionUID = 1L;
@Override
protected void paintComponent(Graphics g) {
try {
BufferedImage img = ImageIO.read(new File(this.getClass().getResource("1.jpg").getPath()));
g.drawImage(img, 0, 0, this.getWidth(), this.getHeight(), null);
} catch (IOException e) {
e.printStackTrace();
}
}
};
左上角的图片好像是setIcon方法设置的
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2013-07-21
展开全部
setUndecorated(true);//去掉边框 setIconImage(image); //设置图标
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
这是我找到的例子
import java.awt.Image;
import java.awt.Rectangle;
import java.awt.TextArea;
import java.awt.Toolkit;import javax.swing.*;public class BgImage extends JFrame {
// 定义图片
private ImageIcon bgImg = new ImageIcon(this.getClass().getResource(
"/1.jpg"));// 图片路径不要写错了 private JPanel mainJPanel = null; private JPanel centerJPanel = null; private JLabel imgLabel = new JLabel(bgImg); // 构造方法
public BgImage() {
initialize(); } private void initialize() { /*
* 自定义图形左上角的图片
*/
Toolkit tk = Toolkit.getDefaultToolkit();
Image i = tk.getImage(this.getClass().getResource("/leave.jpg"));
this.setIconImage(i);
/*
* 取消窗口的边框
*/
this.setUndecorated(true);
this.getRootPane().setWindowDecorationStyle(0); this.setSize(640, 800);
this.setResizable(false);//右上角的变大按钮失效 this.add(getcenterJpanel()); // 把图片设为JFrame背景
this.getLayeredPane().add(imgLabel, new Integer(Integer.MIN_VALUE)); imgLabel.setBounds(0, 0, bgImg.getIconWidth(), bgImg.getIconHeight()); ((JPanel) getContentPane()).setOpaque(false); // 将JFrame上自带的面板设置为透明,否则背景图片不会显示出来 setSize(bgImg.getIconWidth() + 5, bgImg.getIconHeight() + 35); this.setLocationRelativeTo(null);
} /**
* 得到主面板
*
*/
public JPanel getcenterJpanel() {
if (mainJPanel == null) {
mainJPanel = new JPanel();
mainJPanel.setOpaque(false);// 设置为透明
JLabel passWord = new JLabel("您的密码");
JPasswordField jt = new JPasswordField(8);
jt.setOpaque(false);
mainJPanel.add(passWord);
mainJPanel.add(jt); } return mainJPanel;
} public static void main(String[] args) {
new BgImage().setVisible(true);
}}
import java.awt.Image;
import java.awt.Rectangle;
import java.awt.TextArea;
import java.awt.Toolkit;import javax.swing.*;public class BgImage extends JFrame {
// 定义图片
private ImageIcon bgImg = new ImageIcon(this.getClass().getResource(
"/1.jpg"));// 图片路径不要写错了 private JPanel mainJPanel = null; private JPanel centerJPanel = null; private JLabel imgLabel = new JLabel(bgImg); // 构造方法
public BgImage() {
initialize(); } private void initialize() { /*
* 自定义图形左上角的图片
*/
Toolkit tk = Toolkit.getDefaultToolkit();
Image i = tk.getImage(this.getClass().getResource("/leave.jpg"));
this.setIconImage(i);
/*
* 取消窗口的边框
*/
this.setUndecorated(true);
this.getRootPane().setWindowDecorationStyle(0); this.setSize(640, 800);
this.setResizable(false);//右上角的变大按钮失效 this.add(getcenterJpanel()); // 把图片设为JFrame背景
this.getLayeredPane().add(imgLabel, new Integer(Integer.MIN_VALUE)); imgLabel.setBounds(0, 0, bgImg.getIconWidth(), bgImg.getIconHeight()); ((JPanel) getContentPane()).setOpaque(false); // 将JFrame上自带的面板设置为透明,否则背景图片不会显示出来 setSize(bgImg.getIconWidth() + 5, bgImg.getIconHeight() + 35); this.setLocationRelativeTo(null);
} /**
* 得到主面板
*
*/
public JPanel getcenterJpanel() {
if (mainJPanel == null) {
mainJPanel = new JPanel();
mainJPanel.setOpaque(false);// 设置为透明
JLabel passWord = new JLabel("您的密码");
JPasswordField jt = new JPasswordField(8);
jt.setOpaque(false);
mainJPanel.add(passWord);
mainJPanel.add(jt); } return mainJPanel;
} public static void main(String[] args) {
new BgImage().setVisible(true);
}}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询