I think I will be able to use this effectively, however, I'm struggling to understand how it works on the underneath.
From the tutorials I've seen, I understand that the GridBagLayout splits the area of the component into cells, and then you're able to use GridBagConstraints to define the width/height of the components that re going into the cells (i.e. how many cells that component will occupy), the padding of the compoents in the cells, how the cells are filled etc...
The thing I'm struggling to understand is: Does the GridBagLayout ALWAYS split the parent component into nine cells? This is the picture I've got in my head at the moment:
_____
|_|_|_|
|_|_|_|
|_|_|_|
For what I'm doing, i'm only going to need four cells, and although it's not likely to affect my project directly (I can just set the extra cells to have a weighting of zero), this seems very constricting.
I thought I'd ask, as I may have completely misunderstood, which would lead to terrible, terrible problems down the line.
Please and thank you!
~Fae
Quick question about GridBagLayout
Started by Fae, Aug 19 2010 04:47 AM
4 replies to this topic
#1
Posted 19 August 2010 - 04:47 AM
|
|
|
#2
Posted 19 August 2010 - 05:40 AM
I don' think so. At the gridbagconstraints you define in which row and column it is placed and dependant on what you place where it will dynamically create a grid i assume.
#3
Posted 19 August 2010 - 05:57 AM
Right, I see... I did wonder. It seems that every example I've seen had the nine-grid as an example (of course, some components overlapped to show how width worked). It seemed silly to me to have a strict model like forcing a nine-grid upon us without giving us the option to define our own constraints.
That makes a lot more sense... And makes what I'm doing a lot simpler.
Thank you very much, Oxano ^_^
That makes a lot more sense... And makes what I'm doing a lot simpler.
Thank you very much, Oxano ^_^
#4
Posted 19 August 2010 - 09:55 AM
Did you try reading Sun´s tutorial on that? they usually are really good.
How to Use GridBagLayout (The Java™ Tutorials > Creating a GUI with JFC/Swing > Laying Out Components Within a Container)
How to Use GridBagLayout (The Java™ Tutorials > Creating a GUI with JFC/Swing > Laying Out Components Within a Container)
#5
Posted 20 August 2010 - 03:52 AM
Of course, that was my first port of call. That's what first gave me the image in my head of the 3x3 grid. I can't remember exactly where on their site they had it, but they had an image of the gridbaglayout JFrame with buttons divided into nine squares with red lines, showing that you can have buttons that span multiple of these, but I just thought it was restricted to the default 3x3 fashion, and I thought that, as the programmer, I had to work around this to make my 2x2 grid.
Currently, I'm having problems with permissions, but I'll make a new thread for that. :)
Currently, I'm having problems with permissions, but I'll make a new thread for that. :)


Sign In
Create Account


Back to top









