I have a JFrame(frm) in which I’ve added a JPanel (pnl1)..which in turn has another JPanel(pnl2) inside.. Now I have a JButton (btnThrow) in the pnl2…. Is it possible to add/modify the Objects in frm by clicking btnThrow….
I mean how can I modify/add parent container’s components?
I have a JFrame(frm) in which I’ve added a JPanel (pnl1)..which in turn has
Share
You already know how to add components to a container according to your question. So the only thing that remains is to do this when the button is clicked, which can be achieved by adding an
ActionListenerto the button (JButton#addActionListener). To find the parent in your listener you can either pass a reference to it, or use theActionEvent#getSourceand then search for the parent (Component#getParent). Personally, I would pass a reference