Relevance of jseparator.revalidate() statement

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • anurag275125
    New Member
    • Aug 2009
    • 79

    Relevance of jseparator.revalidate() statement

    Hello Bytes.com members.....

    I write a swing program that automatically re-size the separator. But I didn't understand the significance of jseparator.reva lidate() line in the code.
    here is the code..........

    Code:
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    /* <applet
    code=resize_separator.class
    width=600
    height=600
    >
    </applet> */
    public class resize_separator extends JApplet implements ComponentListener
    {
    	JSeparator js=new JSeparator(JSeparator.VERTICAL);
    	Dimension d=js.getPreferredSize();
    	public void init()
    	{
    		Container c=getContentPane();
    		c.setLayout(new FlowLayout());
    		c.add(new JTextField("Hello from swing!",30));
    		c.add(js);
    		c.add(new JTextField("Hello from swing!",30));
    		addComponentListener(this);
    	}
    	public void componentShown(ComponentEvent e)
    	{
    		js.setPreferredSize(new Dimension(d.width,getSize().height));
    		js.revalidate();       // please explain the line
    	}
    	public void componentResized(ComponentEvent e)
    	{
    		js.setPreferredSize(new Dimension(d.width,getSize().height));
    		js.revalidate();
    	}
    	public void componentMoved(ComponentEvent e){}
    	public void componentHidden(ComponentEvent e){}
    }
    can you please explain the statement??

    thanks....
    Last edited by Markus; Feb 15 '10, 03:33 PM. Reason: Added [code] tags
Working...