I begin in the Java programming language. I would like to make a JFrame and put a background image on it and above the JFrame, I would like to insert widgets : JTextArea , JButton ... but they can not overlap. Here is my code :
public void go() {
cadre = new JFrame("Premiere Feneêtre");
cadre.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
cadre.setSize(600, 600);
cadre.setVisible(true);`
BorderLayout agencement = new BorderLayout();
JPanel arrierePlan = new JPanel(agencement);
arrierePlan.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
Box boiteABoutons = new Box(BoxLayout.PAGE_AXIS);
boiteABoutons.setSize(150,150);
boiteABoutons.setOpaque(false);
//boiteABoutons.setBackground(Color.yellow);
b1 = new JButton("Bouton 1");
b1.addActionListener(this);
b2 = new JButton("Bouton 2");
b2.addActionListener(this);
b3 = new JButton("Bouton 3");
boiteABoutons.add(b1);
boiteABoutons.add(b2);
boiteABoutons.add(b3);
zoneTexte = new JTextArea();
Panneau p1 = new Panneau();
arrierePlan.add(BorderLayout.SOUTH, boiteABoutons);
arrierePlan.add(BorderLayout.NORTH,zoneTexte);
cadre.getContentPane().add(p1);
cadre.getContentPane().add(arrierePlan);
}
public class Panneau extends JPanel {
public void paintComponent(Graphics g){
try {
Image img = ImageIO.read(new File("C:/Users/........png"));
//g.drawImage(img, 10, 10, this);
g.drawImage(img, 10, 10, this.getWidth(), this.getHeight(), this);
} catch (IOException e) {
e.printStackTrace();
}
}
}
I've read several things here regarding this problem I encounter, but nothing really helped me .
Thank you Sorry for bad english