javaswinglayout-managerimageiconnull-layout-manager

Why does my GUI disappear as soon as I initialize an ImageIcon?


So i wanna program a Tic Tac Toe game in java.

Now uppon clicking a button, i wanna set the Image of the Button to either "cross" or "circle", but as soon as a type following code, the buttons disappear until i hover over them, then they return.

ImageIcon cross = new ImageIcon("Cross.png");

What it looks like without the code above What it looks like with the code above

Project Structure here


Solution

  • I did in fact use null layot for the window

    That's the problem. For a 3 x 3 grid, I'd use a GridLayout. See How to Use GridLayout for further details.