I've been tasked to create a simple matching pairs game (Find the pairs out of six face down cards). For the cards i've created 6 JToggleButtons with the two different states being the face and back of the card, and i've used ImageIcons for the actual images (180 x 300). I've used a GridLayout comprising of a 3 x 6 grid (6 JToggleButtons[cards], 2 JTextFields [display scores] and 2 JButtons[solve & reset]). My problem is that everything is expanding to the full size of each grid cell, which is not what i want at all, as no the cards looks like buttons and not cards. I did ask the same question in another thread but it was in the OOP board, so i'm hoping i'll have more luck here. I was told last time to use setPreferredSize() to alter the size everything (rather than setSize()), but i found this did nothing.
anwyway, you help would be more than appreciated!
Re: GridLayout help
I think you may find BoxLayout to be helpful for you.
Also, something you may have to consider is using multiple panels on your main JFrame. For example, you may have to create a panel to hold all the cards, a panel to hold the scores, and a panel to hold the Solve and Reset buttons.
How I could see this working is by you using a BoxLayout across the PAGE_AXIS, where objects are placed like this...
...along with the LINE_AXIS version of BoxLayout, which places objects like this...
Object A Object B Object C
...so you can get some sort of result like this...
PAGE_AXIS LINE_AXIS --->
| Object A.a Object A.b Object A.c
| Object B.a Object B.b Object B.c
v Object C.a Object C.b Object C.c
Hopefully this would get you a grid effect without the components filling to the entire size.
Hopefully this helps!