SCJP, SCJD,SCWCD,SCDJWS,SCEA 5 MCP-C#, MCP-ASP.NET - http://www.khaledinho.com/ Life is the biggest school
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32651
4
posted
0
This comes up regularly on these fora. The hard part to understand about GridBag is not the layout, but the constraints. The constraints are:
gridX which means column, starting with 0=left, and
gridY which means row, 0=top,
gridwidth, how many columns covered
gridheight, how many rows etc.
weightx, how much it expands left-to-right,
weighty ditto up and down
anchor, which if any side or corner of its space the component clings to
fill, whether it fills its space horizontally, vertically, or both ways
Insets, an object representing the spacing from the edge of its area
ipadx, internal padding between the spaces left-to-right (I think) and last but not least,
ipady, ditto up and down.
Now if you use GridBagConstraints, you have to write myConstraints.gridx = 123; myConstraints.gridy = 234; every time you add a Component. So your consstraints takes up as much space as the rest of the coding. Find a copy of Horstmann & Cornell's book C Horstmann, G Cornell, Core Java 2, 7/e, Vol I-Fundamentals, Santa Clara CA: Sun Microsystems Press (Prentice-Hall) (2004), pages 430ff. Find the class they call GBC. You can now add things like this:- You can download a copy of the GBC class from Horstmann and Cornell here. And I like the tool which Khaled Mahmoud quoted.
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.