3 Replies Latest reply: May 2, 2013 3:08 PM by TPD-Opitz RSS

    grouplayout with defaulttable model

    993724
      hi,
      I am facing a problem while creating a table with default table model and using the group layout to lay all the components on the frame
      all the things are okay for compiling the program as I want but the problem is that all the components included in my table are displayed as strings, I want to know the reason without using other layout manager

      the code
      import javax.swing.*;
      import javax.swing.table.*;
      
      /**
       *
       * @author COMPUTER SHOP
       */
      public class JobsFollowUp extends JFrame {
          
          //declare the buttons for adding the job and removing for the last row
          JButton addJobButton = new JButton("Add Job");
          JButton removeJobButton = new JButton("Remove Job");
          
      
          
          //declare the engineer names, attach to combo box
          private  final static String[] engineerNames = {"Mohamad Samy", "Ahmad El_Namoury", "Ahmad Ismail"
                                          ,"Mohamad El_Gazar", "Mohamad Tolba", "Mohamad El_Askary"};
          JComboBox engineerNamesComboBox = new JComboBox(engineerNames);
          
          //declare the plant names, attach to combo box
          private  final static String[] plantNames = {"Qar'a", "A.M LPG", "Shipping"};
          JComboBox plantNamesComboBox = new JComboBox(plantNames);
          
          //declare the progress, attach to combo box
          private  final static String[] progressCases = {"Finished", "In Progress", "Waiting SD"};
          JComboBox progressCasesComboBox = new JComboBox(progressCases);
          
          //declare the job description textField
          JTextField jobDescriptionTextField = new JTextField();
          
          //declare the job description textField
          JTextField jobNoTextField = new JTextField();    
          
          //declare the table row that contains the editable cells
          private final  Object [][] rowData ={{engineerNames,jobDescriptionTextField,
                                                      plantNamesComboBox, progressCases,
                                                      jobNoTextField}
                                              };
              //declare the data for the column header 
          private static final String[] columnNames = {"Engineer Name", "Job Description",
                                                       "Plant Name", "Progress", " Job No."};
          //declare the grouplayout as the layout manager for the panel
          GroupLayout layout;
          //declare the scroll pane for the table
          JScrollPane tableScrollPane;
      
          
      public JobsFollowUp(){
              DefaultTableModel model = new DefaultTableModel(rowData,columnNames) ;
      
                //declare the jobs table
              JTable jobsTable = new JTable();
              jobsTable.setModel(model);
              layout = new GroupLayout(getContentPane());
              getContentPane().setLayout(layout);
              tableScrollPane = new JScrollPane(jobsTable);
              //arrange the icons in the program as needed
              layout.setHorizontalGroup(
                  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                  .addGroup(layout.createSequentialGroup()
                      .addContainerGap()
                      .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                          .addGroup(layout.createSequentialGroup()
                              .addComponent(addJobButton)
                              .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                              .addComponent(removeJobButton))
                          .addComponent(tableScrollPane, 0, 375, Short.MAX_VALUE
                      
                      
                      ))
                      .addContainerGap(15, Short.MAX_VALUE))
              );
              
              //arrange the icons in the vertical grid
              layout.setVerticalGroup(
                  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                  .addGroup(layout.createSequentialGroup()
                      .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                          .addComponent(addJobButton)
                          .addComponent(removeJobButton))
                      .addGap(5)
                      .addComponent(tableScrollPane, 0, 170, Short.MAX_VALUE)
                      .addGap(5, 5, 5))
              );        
                     
      }
      
                                                    {       
          }
          
          public static void main(String[] args)
          {
              JobsFollowUp application = new JobsFollowUp();
              application.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              application.setVisible(true);
              application.setSize(700, 500);
          }    
          
          
          
      }
      Edited by: Mohamad Samy on May 1, 2013 10:22 PM

      Edited by: Mohamad Samy on May 1, 2013 10:27 PM