Solved

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

Posted on 2002-03-09
6
270 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
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
expectj telnet failing 5 45
hibernate jars 4 45
spring jars download 1 35
jsp CRUD operations with and without prepared statement also hibernatge 1 10
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

860 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