header for JTable

public HospitalGUI()
{
     Container cp = getContentPane();
     setTitle("Health Service");
     setSize(700,500);
     cp.setLayout(new BorderLayout());
               
     JPanel p1 = new JPanel(new FlowLayout());
     addPatient = new JButton("Add Patient");
     addMF = new JButton("Add MF");
     addProc = new JButton("Add Proc");
     delePatient = new JButton("Delete Patient");
     deleMF = new JButton("Delete MF");
     deleProc = new JButton("Delete Proc");
     p1.add(addPatient);
     p1.add(addMF);
     p1.add(addProc);
     p1.add(delePatient);         
     p1.add(deleMF);
     p1.add(deleProc);
               
     addPatient.addActionListener(this);
     addMF.addActionListener(this);
     addProc.addActionListener(this);
     delePatient.addActionListener(this);
     deleMF.addActionListener(this);
     deleProc.addActionListener(this);
               
     JPanel p2 = new JPanel(new GridLayout(1,2));

     mfdm = new medicalFacilityDefaultModel(hs);
     tableMF = new JTable(mfdm);
     tableMF.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
               
    tableMF.getSelectionModel().addListSelectionListener(this);
               
    pdm = new patientDefaultModel(hs);
    tablePatient = new JTable(pdm);
    tablePatient.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
               
    p2.add(new JScrollPane(tableMF));
    p2.add(new JScrollPane(tablePatient));
         
    JPanel p3 = new JPanel(new GridLayout(2,1));        
    prdm = new procedureDefaultModel(null);  
    tableProcedure = new JTable(prdm);
    tableProcedure.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);

     p3.add(p2);
     p3.add(new JScrollPane(tableProcedure));

     JPanel p4 = new JPanel(new FlowLayout());
     present = new JButton("Present");
     operate = new JButton("Operate");
     editPatient = new JButton("Edit Patient");
     editMF = new JButton("Edit Med Fac");
     editProc = new JButton("Edit Procedure");
     save = new JButton("Save");
     load = new JButton("Load");
     p4.add(present);
     p4.add(operate);
     p4.add(editPatient);
     p4.add(editMF);
     p4.add(editProc);
     p4.add(save);
     p4.add(load);  
         
     present.addActionListener(this);
     operate.addActionListener(this);
     editPatient.addActionListener(this);  
     editMF.addActionListener(this);  
     editProc.addActionListener(this);
     save.addActionListener(this);
     load.addActionListener(this);          

     cp.add(p1, BorderLayout.NORTH);
     cp.add(p3,BorderLayout.CENTER);
     cp.add(p4,BorderLayout.SOUTH);
               
     setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
               
     Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
     int screenWidth = screenSize.width;
     int screenHeight = screenSize.height;
        
     Dimension frameSize = getSize();
     int x = (screenWidth-frameSize.width) / 2;
     int y = (screenHeight-frameSize.height) / 2;
               
     setLocation(x,y);         
}

The code above will create 3 JTables. I actually intend to place a header for each JTable. How is it done?. I tried several ways seems to go out of shape.

Regards

Eugene
eugene007Asked:
Who is Participating?
 
eugene007Connect With a Mentor Author Commented:
I added this code:

JPanel p10 = new JPanel(new GridLayout(1,2));
p10.add(new JLabel("Medical Facility"));
p10.add(new JLabel("Patient"));

JPanel p11 = new JPanel(new BorderLayout());
p11.add(p10,BorderLayout.NORTH);
p11.add(p2,BorderLayout.CENTER);

now I have a main header for each JTable.
0
 
objectsCommented:
They should have already headers by default
0
 
objectsCommented:
Sorry, thought you meant column headings.
0
All Courses

From novice to tech pro — start learning today.