Results 1 to 11 of 11
Thread: Add panel to parent panel
- 08-31-2010, 05:27 AM #1
Member
- Join Date
- Jan 2010
- Posts
- 24
- Rep Power
- 0
-
Hello. I have a feeling that we're going to need to see code in order to understand what you're doing wrong. The best code to post would be a small compilable and runnable program that attempts do to just this -- add a new JPanel into an existing JPanel on button push -- but does no more, an SSCCE (please see the link).
Often problems of this type stem from using the wrong layout managers, or not calling revalidate and repaint on the JPanel that acts as the container after adding or removing components.
- 08-31-2010, 05:48 AM #3
Member
- Join Date
- Jan 2010
- Posts
- 24
- Rep Power
- 0
can't we do without revalidating and repainting.
i am calling the below mentioned class in the action listener.
Java Code:private class ReadMessage extends AbstractAction { private Integer m_session; private ReadMessage(Integer sessionValue) { m_session = sessionValue; } @Override public void actionPerformed(ActionEvent arg0) { // JComboBox comboBox = (JComboBox)arg0.getSource(); int y = 20; for (int i = 0; i < 4; i++) { JPanel panel = new JPanel(); panel.setPreferredSize(new Dimension(500, 150)); panel.setLayout(new BorderLayout()); panel.setBorder(BorderFactory.createBevelBorder( javax.swing.border.BevelBorder.RAISED, Color.LIGHT_GRAY, Color.LIGHT_GRAY)); panel.add(createSession()); panel1.add(panel); panel.setBounds(10, y, 500, 150); y += 160; } panel1.setPreferredSize(new Dimension(500, ((Integer) m_cmbNoOfSessions .getSelectedItem() * 160 + 20))); //ShiftMasterPanel.this.m_txtNoOfSessionsActionPerformed(arg0, m_session); } }Last edited by LovJava; 08-31-2010 at 05:54 AM.
-
What would motivate you to not revalidate and repaint if it would help solve your problem? It's like saying "can't we do without breathing".
Your code won't compile or run for me, so I find it hard to see what you're doing wrong. Again, please read the link I provided above. Yes, it will take some effort for you to create and post an SSCCE, but the effort will help us to see where your problems are and to help us help you, and thus are worth it.i am calling the below mentioned class in the action listener.
Java Code:private class ReadMessage extends AbstractAction { private Integer m_session; private ReadMessage(Integer sessionValue) { m_session = sessionValue; } @Override public void actionPerformed(ActionEvent arg0) { // JComboBox comboBox = (JComboBox)arg0.getSource(); int y = 20; for (int i = 0; i < 4; i++) { JPanel panel = new JPanel(); panel.setPreferredSize(new Dimension(500, 150)); panel.setLayout(new BorderLayout()); panel.setBorder(BorderFactory.createBevelBorder( javax.swing.border.BevelBorder.RAISED, Color.LIGHT_GRAY, Color.LIGHT_GRAY)); panel.add(createSession()); panel1.add(panel); panel.setBounds(10, y, 500, 150); y += 160; } panel1.setPreferredSize(new Dimension(500, ((Integer) m_cmbNoOfSessions .getSelectedItem() * 160 + 20))); //ShiftMasterPanel.this.m_txtNoOfSessionsActionPerformed(arg0, m_session); } }
Again, much luck.
- 08-31-2010, 06:36 AM #5
Member
- Join Date
- Jan 2010
- Posts
- 24
- Rep Power
- 0
i mean it with the visiblity mode?What would motivate you to not revalidate and repaint if it would help solve your problem? It's like saying "can't we do without breathing".
- 08-31-2010, 06:56 AM #6
Member
- Join Date
- Jan 2010
- Posts
- 24
- Rep Power
- 0
Initially in the parent class constructor i am defining the resourseMap for labels . In the previous defined class createSession() , inturn gives the panel with some fields .In the main parent when i select combo box with values 1-5 .The action listner calls that previous class. Now i am able to add dynamically but the problem is am not able to view the resources(labels).
-
Again, without a small testable example program, one that just shows JLabels or JPanels on button push and does nothing else (no database connection, no internet connection), I don't think that there's much help that we have to offer. If you are still stuck, again please look at this link: SSCCE, try to create and post one, and your chances of our being able to help you will increase greatly.
I wish you much luck!
- 08-31-2010, 01:48 PM #8
Member
- Join Date
- Jan 2010
- Posts
- 24
- Rep Power
- 0
I have JPanels has some components(JTextField, Jbutton ) .I am iterating that panel for some number. i wanted how do i set the value for appropriate action for appropriate panel.Pls help me for this.
-
- 09-01-2010, 12:00 PM #10
Member
- Join Date
- Jan 2010
- Posts
- 24
- Rep Power
- 0
Just give me some tips .Usually in your case how would u do?. I read your sscce ,but in my case there severl other refered class i am calling.So it is difficult to do create example .
- 09-02-2010, 08:43 PM #11
Similar Threads
-
Panel in a panel?
By pahiker in forum AWT / SwingReplies: 1Last Post: 07-05-2010, 11:42 AM -
Adding a panel to a panel
By rclausing in forum New To JavaReplies: 7Last Post: 02-02-2010, 05:56 AM -
how to set the location of a panel?
By jboy in forum New To JavaReplies: 5Last Post: 10-27-2009, 07:24 PM -
How to set Image in Panel ?
By sudmitra in forum New To JavaReplies: 0Last Post: 09-12-2009, 10:07 PM -
panel resizing
By simo_mon in forum AWT / SwingReplies: 1Last Post: 08-15-2009, 02:09 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks