Results 1 to 5 of 5
  1. #1
    casid is offline Member
    Join Date
    Nov 2008
    Posts
    18
    Rep Power
    0

    Default [SOLVED] Layout Problem

    Hi everyone,

    I have this time problem with layout managing , I wanted to use grouplayout but error occurred ("Exception in thread "main" java.lang.IllegalArgumentException: Container must be non-null")

    anyway I changed my mind and decided to use free design (absolute positioning), I set layout as null, I gave x,y coordinates and height and width, till creating panel was ok, after created panel and positioned it, tried to add components however I couldnt see my components in panel. could you tell me what I miss here or any suggestion ,

    Java Code:
    jButton2 = new javax.swing.JButton();
            jTextField1 = new javax.swing.JTextField();
            jButton3 = new javax.swing.JButton();
            jButton1 = new javax.swing.JButton();
          
            jTextField2 = new javax.swing.JTextField();
            jTextField3 = new javax.swing.JTextField();
            jTextField4 = new javax.swing.JTextField();
            jTextField5 = new javax.swing.JTextField();
            jTextField6 = new javax.swing.JTextField();
            jTextField7 = new javax.swing.JTextField();
            jTextField8 = new javax.swing.JTextField();
            jTextField9 = new javax.swing.JTextField();
            jTextField10 = new javax.swing.JTextField();
            jTextField11 = new javax.swing.JTextField();
            
            jLabel1 = new javax.swing.JLabel();
            jLabel2 = new javax.swing.JLabel();
            jLabel3 = new javax.swing.JLabel();
            jLabel4 = new javax.swing.JLabel("Guest ID");
            jLabel5 = new javax.swing.JLabel("Reservation ID");
            jLabel6 = new javax.swing.JLabel("FirstName");
            jLabel7 = new javax.swing.JLabel("SurName");
            jLabel8 = new javax.swing.JLabel("Check-In");
            jLabel9 = new javax.swing.JLabel("Check-out");
            jLabel10 = new javax.swing.JLabel("Room Number");
            jLabel11 = new javax.swing.JLabel("Number of Guest");
            
            jButton4 = new javax.swing.JButton();
            jButton5 = new javax.swing.JButton();
            jButton6 = new javax.swing.JButton();
            
            try 
            {
               // create TableModel for results of query SELECT * FROM authors
               tableModel = new ResultSetTable( JDBC_DRIVER, DATABASE_URL, 
                  USERNAME, PASSWORD, DEFAULT_QUERY );
               tableModel.setQuery( DEFAULT_QUERY );
               jTable1 = new javax.swing.JTable(tableModel);
            } // end try
            catch ( Exception classNotFound ) 
            {
               JOptionPane.showMessageDialog( null, 
                  "MySQL driver not found", "Driver not found",
                  JOptionPane.ERROR_MESSAGE );
               
               System.exit( 1 ); // terminate application
            } // end catch
            catch (ExceptionInInitializerError sqlException ) 
            {
               JOptionPane.showMessageDialog( null, sqlException.getMessage(), 
                  "Database error", JOptionPane.ERROR_MESSAGE );
                     
               // ensure database connection is closed
               tableModel.disconnectFromDatabase();
               
               System.exit( 1 );   // terminate application
            }
            
            jScrollPane1 = new javax.swing.JScrollPane(jTable1, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, 
                    ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER );
            
            setTitle("Hotel Rezervation System");
            
            getContentPane().setLayout(null);
    
            jButton2.setText("Search by ID ");
            
            getContentPane().add(jButton2);
            jButton2.setBounds(30, 640, 140, 20);
            getContentPane().add(jTextField1);
            jTextField1.setBounds(180, 600, 160, 20);
    
            jButton3.setText("Delete by ID");
            
            getContentPane().add(jButton3);
            jButton3.setBounds(30, 680, 140, 20);
    
            
            jScrollPane1.setViewportView(jTable1);
    
            getContentPane().add(jScrollPane1);
            jScrollPane1.setBounds(10, 50, 620, 500);
         
            
            
            jPanel1 = new javax.swing.JPanel();
    
            getContentPane().add(jPanel1);
           
            jPanel1.setBounds(700, 50, 270, 400);
            jPanel1.setBackground(new java.awt.Color(0, 255, 204));
            jPanel1.setLayout(null);
            
            getContentPane().add(jLabel4);
            jPanel1.add(jLabel4);
            jLabel4.setBounds(700, 70, 180, 14);
    
            //jPanel1.add(jLabel5);
            
            
            jButton1.setText("Search by Name");
            getContentPane().add(jButton1);
            jButton1.setBounds(30, 600, 140, 23);
    
            
            getContentPane().add(jTextField2);
            jTextField2.setBounds(180, 640, 70, 20);
            getContentPane().add(jTextField3);
            jTextField3.setBounds(180, 680, 70, 20);
    
            jLabel1.setText("Finding Reservation");
            getContentPane().add(jLabel1);
            jLabel1.setBounds(30, 570, 140, 20);
    
            jLabel2.setText("Reservation Details");
            getContentPane().add(jLabel2);
            jLabel2.setBounds(700, 20, 180, 14);
    
            jLabel3.setText("Show All Guest Details");
            getContentPane().add(jLabel3);
            jLabel3.setBounds(20, 20, 130, 14);
    
            jButton4.setText("Update Guest");
            getContentPane().add(jButton4);
            jButton4.setBounds(700, 470, 150, 23);
    
            jButton5.setText("Update Reservation");
            getContentPane().add(jButton5);
            jButton5.setBounds(700, 520, 150, 23);
            
            jButton6.setText("Add New Guest");
            getContentPane().add(jButton6);
            jButton6.setBounds(700, 570, 150, 23);
       
            jButton1.addActionListener(this);
            jButton2.addActionListener(this);
            jButton3.addActionListener(this);
            jButton4.addActionListener(this);
            jButton5.addActionListener(this);
            jButton6.addActionListener(this);
           
            pack();

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default

    Please don't cross-post the same question in multiple fora without providing links to all the cross-posts. Thank you.

  3. #3
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    8

    Default

    Using the null layout is your problem, IMHO. The decision to use is, usually, the worst possible decision you could make, and your reason for using is worse than most.

    Why don't you decribe how the "window" is to look (with an image if you can post one) and we can suggest a better way. The best, although far from the easiest, in most situations is GridBagLayout (however little some like to hear that).

  4. #4
    hardwired's Avatar
    hardwired is offline Senior Member
    Join Date
    Jul 2007
    Posts
    1,576
    Rep Power
    8

    Default

    Java Code:
            // requires a layout manager
    //        pack();
            setSize(1000,775);
            setVisible(true);

  5. #5
    casid is offline Member
    Join Date
    Nov 2008
    Posts
    18
    Rep Power
    0

    Default

    I tried to publish the image, it gave me the warning not to give link,

    I setSize(1000,750);
    and setVisible(true); already.

    I will try to use grouplayout again. in java api tutorial the layout manager was highly recommend, I should keep trying.
    thanks for your help.

Similar Threads

  1. Stack layout
    By blue404 in forum SWT / JFace
    Replies: 0
    Last Post: 03-22-2009, 01:15 PM
  2. Gridbag layout
    By ramesh.8189 in forum New To Java
    Replies: 2
    Last Post: 02-13-2009, 06:21 PM
  3. Help with JButton and layout
    By adlb1300 in forum AWT / Swing
    Replies: 1
    Last Post: 12-25-2007, 08:33 AM
  4. JGraph Layout Pro 1.4.0.3
    By levent in forum Java Software
    Replies: 0
    Last Post: 07-31-2007, 06:43 PM

Posting Permissions

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