java swing中GIF图片显示问题
在显示透明的gif图片的时候,不知道什么原因背景显示有问题,背景显示成系统左上角的图案。但是如果换成静态的png格式的透明图片就没有问题什么repaint(),valid...
在显示透明的gif图片的时候,不知道什么原因背景显示有问题,背景显示成系统左上角的图案。
但是如果换成静态的png格式的透明图片就没有问题
什么repaint(),validate(),setvisible()方法都试过了。下面是代码:
public JComponent getLoadingPanel2() { JPanel contentPanel = new JPanel(); JPanel msgPanel = new JPanel(); int x = (frame.getWidth() - 415) / 2; int y = (frame.getHeight() - 135) / 2; ImageIcon icon = new ImageIcon("images/715.gif"); Image image = icon.getImage().getScaledInstance(100, 100, Image.SCALE_DEFAULT); icon.setImage(image); ImageIcon closeIcon = new ImageIcon("images/window-close.png"); Image closeImage = closeIcon.getImage().getScaledInstance(16, 16, Image.SCALE_DEFAULT); closeIcon.setImage(closeImage); contentPanel.setLayout(null); contentPanel.add(msgPanel); JLabel btnCancel = new JLabel(); btnCancel.setBounds(120, 5, 35, 35); btnCancel.setIcon(closeIcon); btnCancel.setBorder(new EmptyBorder(1, 1, 1, 1)); btnCancel.setBackground(null); btnCancel.setPreferredSize(new Dimension(20, 20)); JLabel imgJLabel = new JLabel(); imgJLabel.setBounds(25, 10, 100, 100); imgJLabel.setIcon(icon); msgPanel.setLayout(null); msgPanel.add(btnCancel); msgPanel.add(imgJLabel); msgPanel.setBounds(0, 0, 150, 120); msgPanel.setLocation(x, y); msgPanel.setBackground(new Color(0, 0, 0, 0)); btnCancel.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { LoadingGlassPane.this.loadCount = 1; LoadingGlassPane.this.hidden(); } }); contentPanel.setBackground(new Color(0, 0, 0, 50)); return contentPanel; } 展开
但是如果换成静态的png格式的透明图片就没有问题
什么repaint(),validate(),setvisible()方法都试过了。下面是代码:
public JComponent getLoadingPanel2() { JPanel contentPanel = new JPanel(); JPanel msgPanel = new JPanel(); int x = (frame.getWidth() - 415) / 2; int y = (frame.getHeight() - 135) / 2; ImageIcon icon = new ImageIcon("images/715.gif"); Image image = icon.getImage().getScaledInstance(100, 100, Image.SCALE_DEFAULT); icon.setImage(image); ImageIcon closeIcon = new ImageIcon("images/window-close.png"); Image closeImage = closeIcon.getImage().getScaledInstance(16, 16, Image.SCALE_DEFAULT); closeIcon.setImage(closeImage); contentPanel.setLayout(null); contentPanel.add(msgPanel); JLabel btnCancel = new JLabel(); btnCancel.setBounds(120, 5, 35, 35); btnCancel.setIcon(closeIcon); btnCancel.setBorder(new EmptyBorder(1, 1, 1, 1)); btnCancel.setBackground(null); btnCancel.setPreferredSize(new Dimension(20, 20)); JLabel imgJLabel = new JLabel(); imgJLabel.setBounds(25, 10, 100, 100); imgJLabel.setIcon(icon); msgPanel.setLayout(null); msgPanel.add(btnCancel); msgPanel.add(imgJLabel); msgPanel.setBounds(0, 0, 150, 120); msgPanel.setLocation(x, y); msgPanel.setBackground(new Color(0, 0, 0, 0)); btnCancel.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { LoadingGlassPane.this.loadCount = 1; LoadingGlassPane.this.hidden(); } }); contentPanel.setBackground(new Color(0, 0, 0, 50)); return contentPanel; } 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询