I've made a Sudoku program but I have 1 issue I can't fix. I have 4 buttons overall but only one appears unless I hover over the others. I know this has something to do with the setLayout option but I don't know how to fix it without making a mess of my display. I don't usually ask for a full solution but if someone can give me a huge hand then I'll be very thankful for it. Sorry that the code is huge... I'm at the end of this project and I'm really lost with this last problem. Here is the main part where the buttons happen:
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.border.Border;
public class Test extends JFrame implements ActionListener {
public static JPanel Container1;
public static JPanel Container2;
public static JPanel containermain;
public static JLabel FOND_ECRAN;
public static JButton verify = new JButton("Verify");
public static JButton solve = new JButton("Solve");
public static JButton reset = new JButton("Reset");
public static JButton submit = new JButton("Submit");
public static JTextField[][] cases = new JTextField[9][9];
public static int[][] NOMBRES_DEBUT;
public static void main(String[] args) {
Test t = new Test();
}
public Test(){
NOMBRES_DEBUT = new int[9][9];
//Permet d'avoir une fenêtre en plein-écran
//this.setUndecorated(true);
this.setAlwaysOnTop(true);
this.setResizable(false);
Toolkit tk = Toolkit.getDefaultToolkit();
int xsize = (int) tk.getScreenSize().getWidth();
int ysize = (int) tk.getScreenSize().getHeight();
this.setSize(xsize, ysize);
Container1 = new JPanel(); //Initialisation de la grille de Sudoku en JTextField
Container1.setLayout(null);
Container1.setBounds((this.getWidth()/2)-(9*60/2),(this.getHeight()/2)-(9*60/2),9*60,9*60);
Container1.setBackground(Color.white);
for (int li = 0; li < 9; li++) { //Rempli les JTextField avec les nombres dans NOMBRES_DEBUT
for (int col = 0; col < 9; col++){
//Things here
}
}
// Création des 4 boutons
int xButton = 170;
int yButton = (int) ((xButton*3)/4);
verify.setBounds((xsize/4)-(xButton/2), (ysize/4)-(yButton/2), xButton, 3*yButton/4);
verify.addActionListener(this);
verify.setBackground(new Color(50, 150, 251));
verify.setOpaque(true);
verify.setBorderPainted(true);
solve.setBounds((xsize/4)-(xButton/2), (ysize/2)-(yButton/2), xButton, 3*yButton/4);
solve.addActionListener(this);
solve.setBackground(new Color(50, 150, 251));
solve.setOpaque(true);
solve.setBorderPainted(true);
reset.setBounds((xsize/4)-(xButton/2), (3*ysize/4)-(yButton/2), xButton, 3*yButton/4);
reset.addActionListener(this);
reset.setBackground(new Color(50, 150, 251));
reset.setOpaque(true);
reset.setBorderPainted(true);
submit.setBounds((xsize/2)-(xButton/2), (7*ysize/8)-(yButton/2), xButton, 3*yButton/4);
submit.addActionListener(this);
submit.setBackground(new Color(50, 150, 251));
submit.setOpaque(true);
submit.setBorderPainted(true);
containermain = new JPanel();
containermain.setBounds(0,0, xsize, ysize);
containermain.setOpaque(false);
containermain.setLayout(null);
// Crée et ajoute le fond d'écran au JLabel
FOND_ECRAN = new JLabel();
FOND_ECRAN.setBounds(0, 0, 1920, 1080);
containermain.add(FOND_ECRAN);
containermain.add(verify);
containermain.add(solve);
containermain.add(reset);
containermain.add(submit);
// Récupère l'image de l'ordinateur
ImageIcon temp = new ImageIcon("C:\\Users\\Maxime\\Documents\\Perso\\Post-Bac\\INSA\\Projet Info\\nature-1520704451453-7117.jpg");
Image img = temp.getImage();
ImageIcon imageIcon = new ImageIcon(img);
FOND_ECRAN.setIcon(imageIcon); // Donne l'image comme fond d'écran
setContentPane(containermain);
containermain.add(Container1);
this.setVisible(true);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
@Override
public void actionPerformed(ActionEvent e) {
// Things happen
}
}