This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes EJB and other Java EE Technologies and the fly likes JPanel is not getting refreshed Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "JPanel is not getting refreshed" Watch "JPanel is not getting refreshed" New topic

JPanel is not getting refreshed

Sherin Dsouza

Joined: Oct 10, 2007
Posts: 1
Hey All,
When a Combo box is clicked I want it to be replaced as a label but in the same frame!!
My code currently refreshes it bu creates a totally new frame.Kindly help!!

package components;

import javax.swing.JPanel;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JFrame;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
* @author user1
public class TestCombo implements ActionListener {
private JPanel testPanel;
private JComboBox testCombo;
private JLabel testLabel;
private JFrame testFrame = new JFrame("Test Combo");
private String msg="default";
/** Creates a new instance of TestCombo */
public TestCombo() {

public JPanel createContentPane()
testPanel=new JPanel();
String[] frequencyVal={"Select","Daily","Weekly","Monthly","Bi-Monthly"};
testCombo=new JComboBox(frequencyVal);
return testPanel;

private void createAndShowGUI() {
//Create and set up the window.


//Create and set up the content pane.
TestCombo test=new TestCombo();

//Display the window.
testFrame.setSize(450, 260);
public void actionPerformed(ActionEvent e) {
JComboBox comboBox=(JComboBox)e.getSource();
String val=comboBox.getSelectedItem().toString();
//TestDailyPanel Contains nothing but a label
TestDailyPanel dailyPanel= new TestDailyPanel();
testFrame.setSize(450, 260);

public static void main(String args[]){
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
TestCombo testCombo=new TestCombo();

Fabian Gutierrez

Joined: Aug 15, 2004
Posts: 22

i think this is not the right place for that post, however, you could try using testFrame.setContentPane(dailyPanel); instead of testFrame.setContentPane(dailyPanel.createContentPane());


SCJP 1.4, SCWCD 1.4, SCBCD 5, SCJD 5
Don't get me started about those stupid light bulbs.
subject: JPanel is not getting refreshed
Similar Threads
Trying to resolve some odd resizing behavior of objects in GridBagLayout
ComboBox Item Display
Trying to understand how layouts resize
Show JPanel in another class HELP !!!!
nothing shows. what did i forget?