亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

加完圖片按鈕之后,之前的背景就不見了。怎么辦???

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條經驗 獲得超21個贊

frame布局的問題,border布局要設定子view的方位

查看完整回答
反對 回復 2022-10-16
?
HUWWW

TA貢獻1874條經驗 獲得超12個贊

設置JButton透明啊

查看完整回答
反對 回復 2022-10-16
  • 2 回答
  • 0 關注
  • 137 瀏覽
慕課專欄
更多

添加回答

了解更多

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號