I am a new Java Programmer.could you help me in resolving this.
I am trying to created a JPanel withing a main JPanel. For the nested one, i have included Grid Layout and i am trying to add components to it dynamically.
i.e i have added a combo box to the nested JPanel and based on the selection it makes, i want to add few more components to the same JPanel.
For this i created some code, but the problem is irrespective of the size, i mention for the combo box, it takes up the whole size of the JPanel and hence, the other components which needs to get added to the panel, based upon the selection of the combo box, are not getting added to the JPanel.
I searched through the net and understood that this has something to do with the layout manager only. But i am unable to debug this out..
Please help me with this
Note - while running the code, please enter the number of rows to be added as 1, since ive not yet handled multiple rows
Also, i would like to include multiple such panels arranged vertically growing downwards. Could someone suggest some idea for that.
The constraint in this case is, at first ill go and add 10 rows and then later depending on my requirement, ill go and delete a particular row in the middle (say 5th) using the delete button, which would be provided at last of every row, so the rows must get rearranged in order to fill the gap made by the removal on the middle row. Please help me with this too..
Now i again tried starting it over and still facing the same issue.
Am, sorry if i am sounding crazy, since i am a newbie to this.i know i am messing up with the code.
As you had said, ive posted only the nested JPanel which is actually posing the problem
The main JPanle is named as Panel, which is added to a frame.
Since i need multiple panels within this Panel, i had used an array of JPanels within this Panel.
This array is the panels.
And i thought the combo[inc].setSize and setBounds, does the same thing, where the latter in addition to setting the size fixes the x and y coordinate within the panel. I tried adding both since i thought either of that might work for me.
Now regardless of whatever i attempt to modify, the nested panel adds only the combo box and makes the combo box to fit the whole size of the frame and hence after selecting the choice, i am unable to add the textbox, through the function offerNameChange.
as you had suggested, i added the System.out.println to check the flow through the item listener, and the flow was completed till the end since all the messages were printed.
And i am sorry, actually i was having some timeline to show some progress and so i posted it in the other forum, but i didnt get any answer from the other one till now.
There are several issues with your code. First of all, you are not setting any layouts to the main panel - this means, the main panel uses FlowLayout. Do you know how FlowLayout handles the components? You just need to call setPreferredSize...
And, you are calling setBounds on the panel - I don't know how FlowLayout handles location of components, but logically, you are adding new panels to the same 'location' and with same size - so, you will have all panels one over the other...
and you should use actionListener for the combo box too unless you need to deal with old and new values (I think ItemListener fires events twice - once for old and new values).