Results 1 to 3 of 3

Thread: [RESOLVED] JAVA 6 GroupLayout

  1. #1

    Thread Starter
    Member
    Join Date
    Sep 2005
    Posts
    54

    Resolved [RESOLVED] JAVA 6 GroupLayout

    Hello,
    could anyone please tell me what is wrong with this code
    code compiles but throw exception at runtime.

    Code:
    import java.awt.*;
    import javax.swing.*;
    public class TestGroup extends JFrame{
    	JTextField UserText, PasswordText ;
    	JLabel UserLabel, PasswordLabel ;
    	JPanel pnl ;
    	public static void main( String[] args ) {
            TestGroup test = new TestGroup();
            test.start();
    	}
    
    	void start(){
    		this.getContentPane().setLayout( new FlowLayout() ) ;
    
    		UserText = new JTextField() ;
    		PasswordText = new JTextField() ;
    		pnl = new JPanel() ;
    
                    GroupLayout lout = new GroupLayout( pnl ) ;
    		pnl.setLayout( lout ) ;
    		lout.setAutoCreateGaps( true ) ;
    		lout.setAutoCreateContainerGaps( true ) ;
    		GroupLayout.SequentialGroup hgroup = lout.createSequentialGroup() ;
    		hgroup.addGroup( lout.createParallelGroup().addComponent(UserLabel).addComponent( PasswordLabel ) ) ;
                    hgroup.addGroup( lout.createParallelGroup().addComponent( UserText).addComponent( PasswordText ) );
    		
    		lout.setHorizontalGroup( hgroup ) ;
    
    
    
    		GroupLayout.SequentialGroup vgroup = lout.createSequentialGroup() ;
    
    		vgroup.addGroup( lout.createParallelGroup().addComponent( UserLabel ).addComponent( UserText ) ) ;
    		vgroup.addGroup( lout.createParallelGroup().addComponent( PasswordLabel ).addComponent( PasswordText ) );
    		
    		lout.setVerticalGroup( vgroup ) ;
            
            	this.getContentPane().add( pnl ) ;
    		this.setSize( 500, 500 ) ;
    		this.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE ) ;
                    this.setVisible( true );
    	}
    }




    Error :

    Exception in thread "main" java.lang.IllegalArgumentException: Component must be
    non-null
    at javax.swing.GroupLayout$ComponentSpring.<init>(Unknown Source)
    at javax.swing.GroupLayout$ComponentSpring.<init>(Unknown Source)
    at javax.swing.GroupLayout$Group.addComponent(Unknown Source)
    at javax.swing.GroupLayout$ParallelGroup.addComponent(Unknown Source)
    at javax.swing.GroupLayout$ParallelGroup.addComponent(Unknown Source)
    at javax.swing.GroupLayout$Group.addComponent(Unknown Source)
    at javax.swing.GroupLayout$ParallelGroup.addComponent(Unknown Source)
    at TestGroup.start(TestGroup.java:24)
    at TestGroup.main(TestGroup.java:9)

  2. #2
    Arabic Poster ComputerJy's Avatar
    Join Date
    Nov 2005
    Location
    Happily misplaced
    Posts
    2,513

    Re: JAVA 6 GroupLayout

    You forgot to initialize the components PasswordLabel and UserLabel before using them
    "I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
    My Blog

  3. #3

    Thread Starter
    Member
    Join Date
    Sep 2005
    Posts
    54

    Re: JAVA 6 GroupLayout

    oooooooooops silly mistake

    thank you very much, my focus was on the grouplayout thats why i could not see that. it was running well if i comment that grouplayout portion so i thought i have done something wrong there only.

    thanks again.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width