JFrame isn't updated with a call to show! What gives?
2 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Anonymous
Posted On:   Friday, June 21, 2002 06:39 AM

I have a JFrame with a bunch of components in it. I want to dynamically change to contents of the JFrame when the user presses som JRadioButtons. Problem is when I change the components in the screen and then call show() on the frame nothing happens!. The components that I've removed can no longer be targeted, but they still appear on the gui!? If i resize the frame the changes that I've made take place?? Eventhough I use the same methods to redraw the Frame! I'm at a total loss. class Opret extends JFrame implements ActionListener { ... JCheckBox bevilling; ButtonGroup type = new ButtonGroup (); JPanel radioPanel = new JPanel(); JButton opretButton; JRad   More>>


I have a JFrame with a bunch of components in it. I want to dynamically change to contents of the JFrame when the user presses som JRadioButtons. Problem is when I change the components in the screen and then call show() on the frame nothing happens!. The components that I've removed can no longer be targeted, but they still appear on the gui!? If i resize the frame the changes that I've made take place?? Eventhough I use the same methods to redraw the Frame! I'm at a total loss.


			

class Opret extends JFrame implements ActionListener
{
...
JCheckBox bevilling;
ButtonGroup type = new ButtonGroup ();
JPanel radioPanel = new JPanel();
JButton opretButton;
JRadioButton elevCheck = new JRadioButton ("Elev");
JRadioButton lærerCheck = new JRadioButton("Lærer");
JRadioButton motorCheck = new JRadioButton("Motorsagkyndig");
JLabel kortTyperLabel;
TeoriProever proever;
JTextField fornavn;
JLabel fornavnLabel;
...
JPanel contentPanel = new JPanel();

Opret ()
{
...
new ComponentAdapter()
{
public void componentResized(ComponentEvent ce)
{
WIDTH = getWidth();
HEIGHT = getHeight();
if (elevCheck.isSelected())
removeButtons();
setupElevButtons();
...
show();
}
...
public void actionPerformed(ActionEvent e)
{
if (e.getSource()== elevCheck)
{
elevSkærm();
}
...
}
...
protected void elevSkærm ()
{
removeButtons();
setupElevButtons();
show();
}
...
protected void removeButtons()
{
try{contentPanel.remove(fornavn);}catch(Exception e){}
try{contentPanel.remove(fornavnLabel);}catch(Exception e){}
try{contentPanel.remove(efternavn);}catch(Exception e){}
try{contentPanel.remove(efternavnLabel);}catch(Exception e){}
try{contentPanel.remove(telefonNr);}catch(Exception e){}
try{contentPanel.remove(tlfLabel);}catch(Exception e){}
...
bevilling = null;
type = null;
opretButton = null;
kortTyperLabel = null;
fornavn = null;
fornavnLabel = null;
efternavn = null;
efternavnLabel = null;
...
}
...
protected void setupElevButtons ()
{
opretButton = new JButton ("Opret");
bevilling = new JCheckBox("Bevillings Elev");
kortTyperLabel = new JLabel ("Kørekorttyper");
fornavn = new JTextField ("");
fornavnLabel = new JLabel ("Fornavn:");
efternavn = new JTextField ("");
efternavnLabel = new JLabel ("Efternavn:");
telefonNr = new JTextField ("");
...
contentPanel.setLayout (new AbsoluteLayout());
addItem (opretButton, .4, .85, .2, .05);
opretButton.addActionListener(this);

addItem (fornavnLabel, .1, 0, .1, .03);
addItem (fornavn, .25, 0, .2, .03);
addItem (efternavnLabel, .5, .0, .1, .03);
addItem (efternavn, .6, .0, .2, .03);
addItem (tlfLabel, .1, .05, .1, .03);
addItem (telefonNr, .25, .05, .2, .03);
...
}



The formatting is a bit screwed up, but should be readable.
If anyone is able to understand the code and see where I go wrong help would be greatly appreciated.

- Peter

   <<Less

Re: JFrame isn't updated with a call to show! What gives?

Posted By:   Lunkwill_Vroomfondel  
Posted On:   Friday, June 21, 2002 09:17 AM

call contentPanel.validate() and contentPanel.repaint()

Re: JFrame isn't updated with a call to show! What gives?

Posted By:   Lunkwill_Vroomfondel  
Posted On:   Friday, June 21, 2002 09:17 AM

call contentPanel.validate() and contentPanel.repaint()
About | Sitemap | Contact