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)




Reply With Quote