当我设置背景时,我无法看到我的按钮,直到我将光标移过它们.. 我试图为按钮设置 setOpaque(true) 但它不起作用..
final JFrame f1=new JFrame("Front Main");
f1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel p1=new JPanel(new GridBagLayout()){
private Image img = ImageIO.read(new File("C:\\Users\\DELL\\Desktop\\football.jpg"));
public void paint( Graphics g ) {
super.paintComponents(g);
g.drawImage(img, 0,0,1366,730, null);
}
};
GridBagConstraints g1= new GridBagConstraints();
JButton b1=new JButton("Admin");
JButton b2=new JButton("User");
JLabel l1=new JLabel("Login as:");
g1.insets=new Insets(3,3,0,0);
g1.weightx=1;
g1.ipadx=200;
g1.anchor=GridBagConstraints.NORTH;
g1.gridwidth=GridBagConstraints.RELATIVE;
p1.add(b1,g1);
g1.anchor=GridBagConstraints.NORTH;
g1.gridwidth=GridBagConstraints.REMAINDER;
p1.add(b2,g1);
g1.weightx=3;
g1.ipadx=0;
p1.add(l1,g1);
f1.add(p1);
p1.setOpaque(false);
f1.setSize(1366,730);
f1.setVisible(true);