Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (498)
Games in Android Showcase (115)
games submitted by our members
Games in WIP (562)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Who wrote that f*** GridLayout?  (Read 2421 times)
0 Members and 1 Guest are viewing this topic.
Offline Serethos

Junior Member




Java games rock!


« Posted 2006-03-07 15:58:57 »

I have a JFrame with a BorderLayout and set a JPanel to its center. This panel has a GridLayout with some components.
When I start the frame with a pack()-size, everything is ok. But when the frame's size gets changed smaller, the whole thing
messes up: all components get disordered. But the best is, after widening the frame, this crap order persists.
I aksed for a solution in another forum, but I only got this (sad, but funny too) adress :
http://madbean.com/anim/totallygridbag

Does anyone know a workaround?
Offline c_lilian

Senior Member


Projects: 1


Java games will probably rock someday...


« Reply #1 - Posted 2006-03-07 16:05:57 »

hehe look like your talking about GridBagLayout

gridlayout is so simple you can't mess anything with it (well I don't use it as it's not powerful enough so I might be wrong).

Have a look at FormLayout from jgoodies : it supports better resizing and is quite simple to use.

Lilian

Offline CaptainJester

JGO Knight


Medals: 12
Projects: 2
Exp: 14 years


Make it work; make it better.


« Reply #2 - Posted 2006-03-07 16:11:21 »

Can you provide a couple of screen shots about what your problem is?

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Serethos

Junior Member




Java games rock!


« Reply #3 - Posted 2006-03-07 18:29:37 »

yepp, i know its not the GridBagLayout, but it was said they they have problems in common. furthermore its a funny
clip.  i have made some screenshots:

at start, all ok:


resized (smaller), elements are disordered:


resized again (larger), still disorder:
Offline jbanes

JGO Coder


Projects: 1


"Java Games? Incredible! Mr. Incredible, that is!"


« Reply #4 - Posted 2006-03-07 18:46:24 »

yepp, i know its not the GridBagLayout, but it was said they they have problems in common.

No they don't. GridBagLayout and GridLayout are entirely different.

Quote
clip.  i have made some screenshots:

I don't really see what the problem is. Make the Window smaller vertically, and life will be roses.

Just an FYI, Java layout managers all draw components so that the fill the entire area. In this case your grid cells are large, so GridLayout fills the cells with the components. If you don't want the components to do this (e.g. you want lots of extra space around them) either find a third party layout manager that does what you need, or write your own. Smiley

P.S. Frame.pack() will auto-fix the window size for you.

Java Game Console Project
Last Journal Entry: 12/17/04
Offline CaptainJester

JGO Knight


Medals: 12
Projects: 2
Exp: 14 years


Make it work; make it better.


« Reply #5 - Posted 2006-03-07 19:02:28 »

Just an FYI, Java layout managers all draw components so that the fill the entire area. In this case your grid cells are large, so GridLayout fills the cells with the components. If you don't want the components to do this (e.g. you want lots of extra space around them) either find a third party layout manager that does what you need, or write your own. Smiley

P.S. Frame.pack() will auto-fix the window size for you.

You don't even need to do that.  You can just put that panel in the east of another panel.  Then put the second panel in the north instead of center.

Offline jbanes

JGO Coder


Projects: 1


"Java Games? Incredible! Mr. Incredible, that is!"


« Reply #6 - Posted 2006-03-07 19:17:32 »

You don't even need to do that.  You can just put that panel in the east of another panel.  Then put the second panel in the north instead of center.

I'm not following you.

1. He only has one panel.
2. That would generate a layout with one panel above the other. Why not just use North and South?

Java Game Console Project
Last Journal Entry: 12/17/04
Offline Mr_Light

Senior Member


Medals: 1


shiny.


« Reply #7 - Posted 2006-03-07 19:36:32 »

normal ppl use a springlayout

because north and south use up the minimal size while the center one takes up what ever space is left north and center makes sense.
Quote
Version note: Before 1.4, the preferred names for the various areas were different, ranging from points of the compass (for example, BorderLayout.NORTH for the top area) to wordier versions of the constants we use in our examples. The constants our examples use are preferred because they are standard and enable programs to adjust to languages that have different orientations.
oooh poor me use page start and center.  Cool

I don't really see what the problem is.
hmm actually looking at it again, the text field at 1,2 suddenly end up at location 2,2 etc.
can you show me the code where you add the components?

It's harder to read code than to write it. - it's even harder to write readable code.

The gospel of brother Riven: "The guarantee that all bugs are in *your* code is worth gold." Amen brother a-m-e-n.
Offline sunsett

Senior Member




ribbit!


« Reply #8 - Posted 2006-03-07 20:39:26 »

You might try TableLayout....it's what I use and has a lot more capabilities than GridBagLayout and MUCH easier to use.

http://jcommon.dev.java.net

-Matt Hicks
Offline Kova

Senior Member





« Reply #9 - Posted 2006-03-07 22:12:00 »

TableLayout... it's what I used instead of gridbag layout. You have excellent control over sizes and resizing.
https://tablelayout.dev.java.net/ ... the tutorial is quite good and not too big.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline sunsett

Senior Member




ribbit!


« Reply #10 - Posted 2006-03-08 16:01:10 »

Kova,

Actually, the TableLayout you refer to is different from the one I referenced.  I actually used to use that one but switched to the one in JCommon because it's much easier to use and much more flexible.

-Matt Hicks
Offline CaptainJester

JGO Knight


Medals: 12
Projects: 2
Exp: 14 years


Make it work; make it better.


« Reply #11 - Posted 2006-03-08 16:35:59 »

You don't even need to do that.  You can just put that panel in the east of another panel.  Then put the second panel in the north instead of center.

I'm not following you.

1. He only has one panel.
2. That would generate a layout with one panel above the other. Why not just use North and South?
I mean if he wants to make it so that his widgets don't change size, he could put a panel within a panel within another panel. 

Panel 1 is GridLayout
Panel 2 is BorderLayout and panel 1 is put in the north
Panel 3 is BorderLayout and panel 2 is put in the west.
 - panel 3 is placed in the content pane for the JFrame in the center.

Now you change the size of the frame all you want and the original Panel 1 will not change size.

Offline Serethos

Junior Member




Java games rock!


« Reply #12 - Posted 2006-03-09 12:25:46 »

I am still a little confused, becaus I reall do not understand why the GridLayout behaves like this.

Quote
I don't really see what the problem is. Make the Window smaller vertically, and life will be roses.

Just an FYI, Java layout managers all draw components so that the fill the entire area. In this case your grid cells are large, so GridLayout fills the cells with the components. If you don't want the components to do this (e.g. you want lots of extra space around them) either find a third party layout manager that does what you need, or write your own. Smiley

Huh? Perhaps I don't understand you suggestion. For testing purposes I added one GridLyout-Panel into the Center of an BorderLayout JFrame(). When I use frame.pack()
it works. But as soon as I modify the size (even if i drag it wider!) it gets disordered. Changing the size, vertically, horizontally, smaller, larger whatever does not restore my
order.
So, wheres the logic? Why does not the order gets the main priority? I think, if the screen gets larger, theres no problem, then all components can be widened too.
If it gets smaller you can shrink all components as far as they all can be displayed. Then you have to cut something off.

Other suggestions to LayoutManagers are nice but for some reasons I need to fix the problem with GridLayout.

Offline Mr_Light

Senior Member


Medals: 1


shiny.


« Reply #13 - Posted 2006-03-09 13:47:14 »

could you show your code / Isolate it in a separate program?

It's harder to read code than to write it. - it's even harder to write readable code.

The gospel of brother Riven: "The guarantee that all bugs are in *your* code is worth gold." Amen brother a-m-e-n.
Offline sunsett

Senior Member




ribbit!


« Reply #14 - Posted 2006-03-09 14:27:31 »

It is really annoying how layout managers force the components to fill the available space sometimes.  The JCommon TableLayout allows you to disable filling on an individual component level or on the entire table.  Also, you may end up having to do something like a FlowLayout inside of a GridLayout if you're sure you want to use GridLayout.

-Matt Hicks
Offline Mr_Light

Senior Member


Medals: 1


shiny.


« Reply #15 - Posted 2006-03-09 22:25:41 »

its not about the suspected behavoir its the unexpected behavoir the order changes.

It's harder to read code than to write it. - it's even harder to write readable code.

The gospel of brother Riven: "The guarantee that all bugs are in *your* code is worth gold." Amen brother a-m-e-n.
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

radar3301 (10 views)
2014-09-21 23:33:17

BurntPizza (28 views)
2014-09-21 02:42:18

BurntPizza (18 views)
2014-09-21 01:30:30

moogie (20 views)
2014-09-21 00:26:15

UprightPath (27 views)
2014-09-20 20:14:06

BurntPizza (29 views)
2014-09-19 03:14:18

Dwinin (46 views)
2014-09-12 09:08:26

Norakomi (74 views)
2014-09-10 13:57:51

TehJavaDev (102 views)
2014-09-10 06:39:09

Tekkerue (50 views)
2014-09-09 02:24:56
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!