Solved

how do I define absolute size and location for a layout?

Posted on 2002-03-09
6
274 Views
Last Modified: 2012-05-04
I'm writing a card game in java, and I have a problem with the GUI: I defined several JPanels on the JFrame, for the card "hands", and used GridBagLayout. Whenever I add a card to the "hand", the whole dimensions of the panel change, and the whole layout changes as well.

How do I set the layout, the parameters, or anything else to define that the dimensions are absolute?
0
Comment
Question by:maor
  • 4
  • 2
6 Comments
 
LVL 3

Expert Comment

by:daitt
ID: 6853900
Using correct layouts and constrains will help you. It depends on your GUI design. Can you describe it here, i.e. draw the layout of your panel?
By the way, setLayout(null) will set the layout to absolute. Then use setBounds(..) to set the location and size of the components.
0
 

Author Comment

by:maor
ID: 6870601
imagine a 6*6 grid. the 6 left squares are a panel, the 6 next to them are a panel, the 6 right squares are a panel, the 6 next to them are a panel. we're left with an area 3 squares wide, 6 squares high. the top 3 are a panel, the 3 below them are a panel. the bottom 3 are a panel, the 3 above are a panel. we're left with a 3*2 area, in which are a couple of other things. let me try and draw it:
 ___  ___  __________________  ___  ___
|   ||   ||                  ||   ||   |
|   ||   ||__________________||   ||   |
|   ||   | __________________ |   ||   |
|   ||   ||                  ||   ||   |
|   ||   ||__________________||   ||   |
|   ||   |                    |   ||   |
|   ||   |                    |   ||   |
|   ||   |                    |   ||   |
|   ||   | __________________ |   ||   |
|   ||   ||                  ||   ||   |
|   ||   ||__________________||   ||   |
|   ||   | __________________ |   ||   |
|   ||   ||                  ||   ||   |
|___||___||__________________||___||___|

did this help to explain things?








0
 

Author Comment

by:maor
ID: 6870602
naturally, ascii art has no place in experts-exchange :)

so try using a bit of imagination here... :)
0
Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

 
LVL 3

Accepted Solution

by:
daitt earned 100 total points
ID: 6870618
I can copy and paste into notepad and imagine your layout.
I'm in a hurry now I cannot test my idea, but try this:
You have three columns GridBagLayout: (2 left panels),(middle panels and areas), (2 right panels).
Use GridLayout to arrange 2 left panels, and another gridlayout to arrange 2 right panels.
Use GridLayout (3 rows) for the middle area: (2 top rows), (middle area), (2 bottom rows).
Use some other GridLayouts for the squares.
Gotta go. Goodluck
0
 

Author Comment

by:maor
ID: 6871864
I'll give both ideas - gridlayouts and setlayout(null) - a try.
however, I still suspect I might have some trouble when adding a card to one of the gridlayouts. any thoughts on how this can be solved?
0
 

Author Comment

by:maor
ID: 7770287
It has been ages since this question went up, and this answer didn't work well.  I have decided to give up on this layout, and switched to a simpler one.
However, breaking this down into panels inside panels inside panels, has provided a partial solution, and it has made my life easier with the new layout.

sorry it took so long, enjoy the points, and thanks :)
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
tomcat administrtor 12 68
mysql jsp example issue 32 74
Java: The Public Class Main 4 45
Delete .class files at every compile 4 21
An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question