HI i ve given a picture and I tried to do that with many layouts but i failed ultimately. Grid bag can solve it seems. Can any body send coding for constructing this structure(shown in picture)
Printable View
HI i ve given a picture and I tried to do that with many layouts but i failed ultimately. Grid bag can solve it seems. Can any body send coding for constructing this structure(shown in picture)
It is considered very rude to cross-post the same question in multiple fora. If you desire more folks to be motivated to help you, I would advise you not to do this.
Fubarable is correct about cross-posting. We also don't provide code. Write some code, post it if you don't understand something specific, and we can try to help you.
GridBagLayout is very powerful, and I'm sure you can use it produce your desired layout. Check out Sun's tutorial, and experiment.
If you are not using an IDE, I suggest getting Netbeans and using the Matisse tool. It has a special function that visually displays the grid and allows you to set constraints for the components in each cell. Or, lay the components out in a spreadsheet. That can help you visualize what you are doing.
Sir i never post without trying. i did that in net beans using Group layout(free design). but dono how to do in Grid Bag,the powerful one. Hence I requested others..
you can still use set the layout manager in netbeans to use gridbag instead of the default one.
its better to hand code the layout in my opinion so you actually understand whats going on. there's a good tutorial from the official sun java tutorial on all layouts found on their website.
I partially agree with Maxim. Don't blindly use a designer without having any idea of what it is doing. On the other hand, I've seen some truly awful hand-coded layout code that showed no comprehension, so hand-coding won't solve all the issues, either.
I assume Netbeans Matisse allows you to view and add to the generated code. I know the Matisse port to Eclipse does. Here is what I suggest.
Create a blank form in Matisse using JFrame.
Set the JFrame layout manager to GridLayout, using the defaults.
Add a JPanel. This will cause the JPanel to fill the content pane.
Change the JPanel layout manager to GridBagLayout. Note that this manager has no properties.
Add 8 labels to the JPanel.
Right click on the GridBagLayout in the Outline and select customize.
Play around in the designer, changing the properties of each component. Start with Grid X and Y values. Watch how setting values rearranges the labels. Make sure to use relative in one dimension while setting the other. Also, watch what happens when using relative if a "cell" is left empty to the left or above a relative component.
Next, try Fill values.
I don't use internal padding.
Change the anchor values.
Combine Fill and Weight to cause certain cells to control the dimensions of their columns and rows. By default, everything will expand to take up the whole JPanel.
Last, set Fill to both and play with insets.