Results 1 to 10 of 10
Thread: Understanding GridBagLayout
- 08-15-2012, 03:36 PM #1
Senior Member
- Join Date
- Dec 2011
- Posts
- 102
- Rep Power
- 0
Understanding GridBagLayout
Hi,
I came across this useful class but couldn't understand how exactly it determines how to divide the frame, because in all the examples I've seen there's never been any declaration for how many cells or what size each row or column should get.
Is there another useful Layout class I should know about?
Thanks :)
- 08-15-2012, 04:45 PM #2
Re: Understanding GridBagLayout
There are many layouts to choose from. I personally use a layout of my own design, but it all depends on what you need it for. I hold a grudge against gridbaglayout, but I have one question before going further. Have you tried this tutorial?
How to Use GridBagLayout (The Java™ Tutorials > Creating a GUI With JFC/Swing > Laying Out Components Within a Container)My API:Java Code:cat > a.out || cat > main.class
- 08-15-2012, 05:07 PM #3
Re: Understanding GridBagLayout
To partly answer your question: GBL allots horizontal/vertical space of each occupied column/row, based on the gridx/y/width/height fields of the GBC with which a component was added to the layout.
Any remaining space is allocated in proportion of the largest weightx/y associated with a component exclusively occupying the column/row (not components that span more than one column/row).
Other properties like anchor, insets, padding and fill are pretty much self-explanatory, but the only way to learn GBL is to use it and play around with the constraints.
An interesting but little noticed feature is that you can retrieve and mutate the GBC for a particular component at runtime.
That said, for anyone who isn't planning to make a living as a GUI designer, a better option is to nest containers, each with their own layout, to achieve a complex layout. And if you do go professional, you'll end up investing the almost absurd amount of time and effort it takes to master a visual designer, and never look at layout code again.
dbWhy do they call it rush hour when nothing moves? - Robin Williams
- 08-15-2012, 05:08 PM #4
Re: Understanding GridBagLayout
Moved from New to Java
dbWhy do they call it rush hour when nothing moves? - Robin Williams
- 08-16-2012, 11:21 AM #5
Senior Member
- Join Date
- Dec 2011
- Posts
- 102
- Rep Power
- 0
Re: Understanding GridBagLayout
Yea, I did see this guide, but only now I get the idea that it gets sized by the components inserted to it.
Maybe I'll take a second look at it and try playing with it once again until I get it.
Thanks.
- 08-16-2012, 11:27 AM #6
Senior Member
- Join Date
- Dec 2011
- Posts
- 102
- Rep Power
- 0
Re: Understanding GridBagLayout
By the way,
I've never really worked at programming or did anything proffesional, but you guys want to tell me that any programmer that isn't really a designer uses nested panels instead of layouts? :| that's a shock.
I mean, it doesn't look proffesional using nested panels, because sometimes you'll have to nest a lot of panels. Doesn't it take too much memory and increases the loading time significantly?
Thanks!
- 08-16-2012, 03:12 PM #7
Re: Understanding GridBagLayout
If you are nesting a lot of panels, maybe there is a method you could use that requires less panels and still reaches the same effect. The layout you choose does not make a GUI look professional, its the programmer who molds it who makes it look professional. I have used every single standard layout (except the one that eclipses uses), for my applications, and I come to find that it is not that one look more or less professional but that they all tools meant for different problems. If you have a complex problem, combining them or even nesting them can help you achieve your goal.
To answer your question about load time, it depends on how big the program is as a whole. I have a game with a huge amount of nested JPanels, and it takes 3-5 seconds to load up. To me that is a long time, but I have not even began to optimize the game. If your GUI is as big as my game, then a loading time of a few seconds (in my opinion) is not that bad of a thing. If it does become a problem, see if there are better methods to laying out your components in your GUI.My API:Java Code:cat > a.out || cat > main.class
- 08-16-2012, 03:42 PM #8
Re: Understanding GridBagLayout
OT: Even the one the Swing layout tutorial doesn't even mention? I've never seen that used, and the description doesn't encourage me to think it's highly usable.
dbWhy do they call it rush hour when nothing moves? - Robin Williams
- 08-16-2012, 03:45 PM #9
Re: Understanding GridBagLayout
To add one more 'feature' of GBL: if unable to provide enough horizontal/vertical space for the preferred width/height, it directly shrinks the component to its minimum width/height.
dbWhy do they call it rush hour when nothing moves? - Robin Williams
- 08-16-2012, 07:42 PM #10
Senior Member
- Join Date
- Dec 2011
- Posts
- 102
- Rep Power
- 0
Similar Threads
-
GridBagLayout vs me: 1 - 0
By JosAH in forum AWT / SwingReplies: 9Last Post: 08-19-2011, 09:18 PM -
GridBagLayout Help
By Zman3359 in forum AWT / SwingReplies: 0Last Post: 02-21-2011, 08:39 PM -
GridBagLayout
By carderne in forum New To JavaReplies: 8Last Post: 01-25-2009, 02:06 PM -
GridBagLayout
By MuslimCoder in forum New To JavaReplies: 1Last Post: 01-15-2009, 08:54 PM -
abt gridbaglayout
By pinky in forum AWT / SwingReplies: 1Last Post: 12-15-2008, 08:35 AM


1Likes
LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks