为了账号安全,请及时绑定邮箱和手机立即绑定

加完图片按钮之后,之前的背景就不见了。怎么办啊?

加完图片按钮之后,之前的背景就不见了。怎么办啊?

陪伴而非守候 2022-10-11 15:11:05
package demo;public class demo_01 {private JDesktopPane desktopPane;private JFrame frame;private JLabel backLabel;private JPanel myPanel;public Toolkit toolkit = Toolkit.getDefaultToolkit() ;public Dimension sc = toolkit.getScreenSize() ;public JLabel name1 = new JLabel("姓 名") ;public JTextField textName1 = new JTextField() ;public Font font1 = new Font("宋体",4,25) ;public demo_01(){frame = new JFrame("测试");frame.addComponentListener(new ComponentAdapter(){public void componentResized(ComponentEvent e){backLabel.setSize(frame.getWidth(),frame.getHeight());backLabel.setText("<html><body><image width='"+frame.getWidth()+"'height='"+(frame.getHeight()-110)+"'src="+demo_01.this.getClass().getResource("tianxiexinxi.jpg")+"'></img></body></html>");}});frame.getContentPane().setLayout(new BorderLayout(5,5));frame.setBounds(0,0,2550,1440);frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);backLabel=new JLabel();backLabel.setVerticalAlignment(SwingConstants.TOP);backLabel.setHorizontalAlignment(SwingConstants.CENTER);frame.setLayout(new BorderLayout(5,5));name1.setForeground(Color.blue);name1.setSize(200,70);name1.setFont(font1) ;name1.setLocation(420, 210);frame.add(name1,BorderLayout.CENTER);name4.setForeground(Color.blue);textName1.setBounds(540, 227, 400, 33);frame.add(textName1);desktopPane=new JDesktopPane();desktopPane.add(backLabel,new Integer(Integer.MIN_VALUE));frame.getContentPane().add(desktopPane);//完成JButton icon1=new JButton(new ImageIcon("res/wancheng.png"));myPanel = new JPanel();myPanel.add(icon1);myPanel.setSize(414, 129);frame.add(myPanel);icon1.setSize(414,129);icon1.setLocation(0, 0);frame.setVisible(true);}public static void main(String[] args) {// TODO Auto-generated method stubSwingUtilities.invokeLater(new Runnable(){@Overridepublic void run() {// TODO Auto-generated method stubnew demo_01();}});}}
查看完整描述

2 回答

?
茅侃侃

TA贡献1842条经验 获得超22个赞

frame布局的问题,border布局要设定子view的方位

查看完整回答
反对 回复 2022-10-16
?
HUWWW

TA贡献1874条经验 获得超12个赞

设置JButton透明啊

查看完整回答
反对 回复 2022-10-16
  • 2 回答
  • 0 关注
  • 157 浏览

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号