Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: GridLayout help

  1. #1
    Junior Member
    Join Date
    Nov 2011
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question GridLayout help

    Hey there,

    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!

    Thanks


  2. #2
    Member snowguy13's Avatar
    Join Date
    Nov 2011
    Location
    In Hyrule enjoying a chat with Demise and Ganondorf
    Posts
    339
    My Mood
    Happy
    Thanks
    31
    Thanked 48 Times in 42 Posts

    Default 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...

    Object A
    Object B
    Object C

    ...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!

Similar Threads

  1. GridLayout and size problems...
    By sambar89 in forum Object Oriented Programming
    Replies: 2
    Last Post: November 6th, 2011, 12:06 PM
  2. Images in GridLayout
    By BuhRock in forum AWT / Java Swing
    Replies: 4
    Last Post: November 5th, 2011, 12:15 AM
  3. [SOLVED] how to get the row and column of a component gridlayout
    By prettynew in forum AWT / Java Swing
    Replies: 0
    Last Post: March 13th, 2011, 06:39 PM
  4. Moving Icon in gridlayout SWING
    By Loodistobilo in forum What's Wrong With My Code?
    Replies: 3
    Last Post: November 24th, 2010, 06:59 PM
  5. [SOLVED] "GridLayout" problem in Java program
    By antitru5t in forum AWT / Java Swing
    Replies: 3
    Last Post: April 16th, 2009, 10:26 AM