Solved

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

Posted on 2002-03-09
6
257 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
Comment Utility
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
Comment Utility
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
Comment Utility
naturally, ascii art has no place in experts-exchange :)

so try using a bit of imagination here... :)
0
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 3

Accepted Solution

by:
daitt earned 100 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Java 1603 Error 2 41
bigHeights  challenge 13 55
strCount chalenge 3 50
micro services vs rest web services 16 44
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
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 learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
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:

728 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now