Foto als JFrame-Hintergrund hinzufügen [duplizieren]
Diese Frage hat hier bereits eine Antwort:
Hintergrundbilder in JFrame @ festleg 4 Antwortenpublic static void main(String[] args) {
myForm.setSize(500, 400);
myForm.setLocation(0, 0);
myForm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
myForm.setVisible(true);
// try {
// myForm.setContentPane(new JLabel(new ImageIcon(ImageIO.read(new File("C:\\Users\\Heshamm\\Desktop\\light.jpg"))) ) );
//} catch (IOException e1) {
//JOptionPane.showMessageDialog(null, "Error !!!", null, JOptionPane.PLAIN_MESSAGE);
//}
draw.mai(myForm, jp1, button, tf[0], tf[1], tf[2], tf[3]);
Und das ist die mai () Funktion in einer anderen Klasse
public void mai(JFrame myForm, JPanel jp1, JButton[] button, JTextField tf1, JTextField tf2, JTextField tf3, JTextField tf4)
{
myForm.getContentPane().removeAll();
jp1.removeAll();
jp1.add(button[0]);
jp1.add(button[1]);
jp1.add(button[2]);
jp1.add(button[3]);
jp1.add(button[9]);
, jp1.add(button[4]);
tf1.setText("");
tf2.setText("");
tf3.setText("");
tf4.setText("");
Hotel.update();
}
Okay also, ich habe diesen Code und ich wollte, dass das Bild als Hintergrund hinter den Schaltflächen angezeigt wird, aber wenn ich versuche das Kommentarzeichen zu entfernen und was darin ist, zeigt der Rahmen nur den Hintergrund ohne die Schaltflächen an. Wie kann ich das Problem beheben?
Und hier ist die update () Funktion.
public static void update()
{
cbChoice="";
myForm.add(jp1);
myForm.repaint();
myForm.revalidate();
}
Danke im Voraus