I am trying to set a JPanel with GridBagLayout and whenever I am trying to add any component in that JPanel , the component is being displayed in the Center Only. If I remove the layout , then the scenario is fine.
My advice is to learn the other layout managers first before attempting to learn how to use the GridBagLayout. Any class that requires you to learn how to set the value of multiple constraints will be more difficult to learn than those that require 0 or 1 one constraint.
Read the section from the Swing tutorial on How to Use GrigBagLayout, which explains the usage of each of the constraints. I think its the weightX/Y that is the problem.
buntha Choudhary wrote:I appreciate your advice but for my project I need to use the GridBagLayout Manager only.
What project, you mean for your school assignment?
Otherwise there is no reason to be forced to use a specific layout manager. That is why multiple layout managers exists. You use the appropriate combination of layout managers to get the desired effect.
Could you post a link to an image that demonstrates what you are trying to accomplish here, what you want your current small app to look like when it's through? Either that or describe the desired result in as much detail as possible.
My Application is very big so I only added a dummy piece of code and now I need to make a form for adding Reminder. I have solved the issue with BorderLayout but problem is , according to the SRS , I need to follow GridBagLayout.
In that form , I need to paste first a Subject Field (1 Row), then Time and Date (Next Line) , then a Combo Box with name and Image(this should cover atleast 5 rows) , then in next line will add a text area for Description(5 rows) , then again after the Text Area , will add Importancy as Combo Box(1 Row) and finally in the end of the Panel , will add a Button for Saving all the above entered records.
Today you are you, that is turer than true. There is no one alive who is youer than you! - Seuss. Tiny ad: