Solved

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

Posted on 2002-03-09
6
282 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
What Is Transaction Monitoring and who needs it?

Synthetic Transaction Monitoring that you need for the day to day, which ensures your business website keeps running optimally, and that there is no downtime to impact your customer experience.

 
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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

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 last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
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 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:

691 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