0

I'm working on a board game for a school project, and the board is something like this :

https://cf.geekdo-images.com/images/pic1331597.jpg

I'm to create tiles for each card, and I'm not sure how to position those in a way that they "fit" the background image.

I was going to use absolute positioning and fixed size for each card JPanel, but I thought it would be a little ugly.

Is there a way to use something like a GridLayout while remaining able to set the position of the JPanel with the layout and it's size ? (and, margins between elements as well ?).

This seems a bit tricky and i'm sure there's plenty of people that probably already encountered the issue.

Thanks in advance for your help

camickr
  • 321,443
  • 19
  • 166
  • 288
  • `margins between elements as well` - you can specify a horizontal/vertical gap between each grid. It will be the same for all grids. If you need a more flexible grid, then you should use `GridBagLayout`. – camickr Jun 17 '17 at 19:19
  • 1
    Possible duplicate of [*Add a complex image in the panel, with buttons around it in one customized user interface*](https://stackoverflow.com/q/10861852/230513). – trashgod Jun 17 '17 at 19:31
  • Assuming the grid cells size is known, you could use a `GridLayout` and fill it with `JLabel`'s (assigned a blank image), which are transparent by default, then you could simply assign the `icon` property of the labels to whatever you want - if `JLabel`s don't provide enough customisation for you, you could use `JPanel`, but just make it transparent (`setOpaque(false)`), then you could add other components to it. Just remember, all of this will affect the size of the components, so you might want to investigate means by which you can make them a fixed sized – MadProgrammer Jun 17 '17 at 23:02

0 Answers0