File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "JPanel is not getting refreshed" Watch "JPanel is not getting refreshed" New topic
Author

JPanel is not getting refreshed

Sherin Dsouza
Greenhorn

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();
testPanel.setLayout(null);
String[] frequencyVal={"Select","Daily","Weekly","Monthly","Bi-Monthly"};
testCombo=new JComboBox(frequencyVal);
testCombo.addActionListener(this);
testCombo.setBounds(150,25,150,25);
testPanel.add(testCombo);
return testPanel;
}

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

testFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

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

//Display the window.
testFrame.setSize(450, 260);
testFrame.setVisible(true);
}
public void actionPerformed(ActionEvent e) {
JComboBox comboBox=(JComboBox)e.getSource();
String val=comboBox.getSelectedItem().toString();
if(val.equals("Daily")){
//TestDailyPanel Contains nothing but a label
TestDailyPanel dailyPanel= new TestDailyPanel();
testFrame.setContentPane(dailyPanel.createContentPane());
testFrame.setSize(450, 260);
testFrame.setVisible(true);
}

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

}
});
}
}
Thanks,
Sherin
Fabian Gutierrez
Greenhorn

Joined: Aug 15, 2004
Posts: 22
hi,

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());

regards,


SCJP 1.4, SCWCD 1.4, SCBCD 5, SCJD 5
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: JPanel is not getting refreshed