Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How do I refresh a JFrame object

843807Aug 16 2005 — edited Aug 18 2005
This is the closest code I could find to redraw the screen when the frame is resized:
	public ImageTest()
	{
		initializeMethod();
		label = new JLabel(new String("Hello"));
		pane = new JPanel();
		pane.add(label);
		add(pane);
		addComponentListener(new ComponentMsgHandler());
	}
	
	
	class ComponentMsgHandler implements ComponentListener
	{
		ComponentMsgHandler(){
		}
		public void componentResized(ComponentEvent e){
			JFrame f = (JFrame)e.getSource();
			f.update(/*f.getGraphics()*/);
			label.setText(String.format("%1d",++c));
		}
		public void componentMoved(ComponentEvent e){
		}
		public void componentShown(ComponentEvent e){
		}
		public void componentHidden(ComponentEvent e){
		}
	}
Although the label gets updated with the correct value for 'c', the JFrame.paint() doesn't redraw. I'm wondering if the problem is with the graphics object I'm passing to f.update()? Is there a proper way to do this?
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Sep 15 2005
Added on Aug 16 2005
1 comment
464 views