1

I am making a board game and need two panels on a JFrame. I added them and they look good enough but one of them, the big grid to play the game, doesn't show all the way, I only see a little, I have to resize the window manually.

I have tried with different layouts and nothing works. This is the code in which I add the components to the frame:

    panel.setSize(500, 100);
    panel.setBackground(Color.WHITE);
    panel.add(botonArriba);
    panel.add(botonAbajo);
    panel.add(botonIzquierda);
    panel.add(botonDerecha);
    panel.setVisible(true);

    this.setDefaultCloseOperation(EXIT_ON_CLOSE);
    this.setLocationRelativeTo(null);
    tablero.setSize(281, 300);
    this.add(tablero, BorderLayout.CENTER);
    this.add(panel, BorderLayout.SOUTH);
    this.setTitle("2048");
    this.pack();
    this.setVisible(true);
0

1 Answer 1

0

Use setPreferredSize(...) which is what the layout manager tries to achieve. Of course the panel needs a LayoutManager too.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.