Adding JButtons to a JPanel which layout is a “GridLayout”?

Here's an implementation using ideas from the comment: public class Main { public static void main(String args) { JFrame frame = new JFrame(); int gridSize = 3; // try 4 or 5, etc. Buttons are always 50x50 JPanel panel = new JPanel(new GridLayout(gridSize, gridSize)); panel. SetPreferredSize(new Dimension(500, 500)); for (int I = 0; I Anchor = GridBagConstraints. CENTER; JButton button = new JButton(); button.

SetPreferredSize(new Dimension(50, 50)); buttonPanel. Add(button, c); panel. Add(buttonPanel); } } frame.

SetContentPane(panel); frame.pack(); frame. SetVisible(true); } }.

1, you've got the idea, although I'm not sure if this is the best implementation. But maybe it is? :) – mre Jul 6 at 18:15 Thanks :) yes that'll do it.

– SpiXel Jul 7 at 5:57.

I have a 30x30 GridLayout of JPanels. So each Cell in the 30x30 Frame is a JPanel with an Image. Aka Tiles on a map.

I need to move my character (red JPanel) around this map on keyPress.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions