Java 将JDialog的内容面板设置为透明后,为什么添加组件后,需要用鼠标点经过后,组件才显示出来。
这是我写的一个类:importjava.awt.Container;importjava.awt.FlowLayout;importjavax.swing.*;publi...
这是我写的一个类:
import java.awt.Container;
import java.awt.FlowLayout;
import javax.swing.*;
public class BackgroupDemo {
public static void main(String[] args) {
// TODO Auto-generated method stub
JDialog dialog = new JDialog();
Icon icon = new ImageIcon("D:\\Backup\\我的文档\\My Pictures\\we.jpg");
JLabel label = new JLabel(icon);
label.setBounds(0, 0, icon.getIconWidth(), icon.getIconHeight());
dialog.setSize(600,500);
dialog.getLayeredPane().add(label, Integer.MIN_VALUE);
Container cp = dialog.getContentPane();
((JPanel)cp).setOpaque(true);
// dialog.setDefaultCloseOperation(JDialog.EXIT_ON_CLOSE);
dialog.setLayout(new FlowLayout());
JButton button1=new JButton("按钮");
JButton button2=new JButton("按钮");
JButton button3=new JButton("按钮");
button1.setOpaque(false);
button2.setOpaque(false);
button3.setOpaque(false);
dialog.getContentPane().add(button1);
dialog.getContentPane().add(button2);
dialog.getContentPane().add(button3);
//dialog.invalidate();
dialog.setVisible(true);
}
} 展开
import java.awt.Container;
import java.awt.FlowLayout;
import javax.swing.*;
public class BackgroupDemo {
public static void main(String[] args) {
// TODO Auto-generated method stub
JDialog dialog = new JDialog();
Icon icon = new ImageIcon("D:\\Backup\\我的文档\\My Pictures\\we.jpg");
JLabel label = new JLabel(icon);
label.setBounds(0, 0, icon.getIconWidth(), icon.getIconHeight());
dialog.setSize(600,500);
dialog.getLayeredPane().add(label, Integer.MIN_VALUE);
Container cp = dialog.getContentPane();
((JPanel)cp).setOpaque(true);
// dialog.setDefaultCloseOperation(JDialog.EXIT_ON_CLOSE);
dialog.setLayout(new FlowLayout());
JButton button1=new JButton("按钮");
JButton button2=new JButton("按钮");
JButton button3=new JButton("按钮");
button1.setOpaque(false);
button2.setOpaque(false);
button3.setOpaque(false);
dialog.getContentPane().add(button1);
dialog.getContentPane().add(button2);
dialog.getContentPane().add(button3);
//dialog.invalidate();
dialog.setVisible(true);
}
} 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询