I'm trying to use gridbagconstraints in a small app that i'm making but for some reason it won't align to the way I want it, here is my source code from my 4 classes
have a look at your FormPanel class, line 24. What do you noticë?
Next, have a careful look at what you specify as GridBagConstraints.gridx and gridy.
So, you do create a JPanel with a GridBagLayout. But is that the JPanel to which you are adding your components?
And indeed: your gridx and gridy need to be different for each component.
mitchell bat wrote:
Yes, because there is no other JPanel created in the application, unless i'm missing something or it doesn't make sense to you?
Are you sure there is only one panel involved? (hint: have a look at your FormPanel class definition)
Your FormPanel IS a JPanel. That is why in the constructor your add(component...) works. It simply adds these components to this instance of FormPanel.
But the default LayoutManager is a FlowLayout, and since you did not replace that Layout (with : setLayout(...)), you are still using this FlowLayout.
Do your text fields appear correctly? I think they will shrink almost to invisibility if you don't give them a HORIZONTAL fill.
mitchell bat wrote:So for this in the ToolBar class line 15 change it from to ?
Well, you could if you feel like it, but personally, I liked the three buttons, neatly side by side in the toolbar! So the FlowLayout seems good enough.
By the way: as far as I know, there is no GridBagLayout constructor that has a parameter.