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
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
 
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?