header for JTable

Posted on 2005-05-16
Last Modified: 2010-05-19
public HospitalGUI()
     Container cp = getContentPane();
     setTitle("Health Service");
     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");
     JPanel p2 = new JPanel(new GridLayout(1,2));

     mfdm = new medicalFacilityDefaultModel(hs);
     tableMF = new JTable(mfdm);
    pdm = new patientDefaultModel(hs);
    tablePatient = new JTable(pdm);
    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);

     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");

     cp.add(p1, BorderLayout.NORTH);
     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;

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.


Question by:eugene007
    LVL 92

    Expert Comment

    They should have already headers by default

    Accepted Solution

    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());

    now I have a main header for each JTable.
    LVL 92

    Expert Comment

    Sorry, thought you meant column headings.

    Featured Post

    How to improve team productivity

    Quip adds documents, spreadsheets, and tasklists to your Slack experience
    - Elevate ideas to Quip docs
    - Share Quip docs in Slack
    - Get notified of changes to your docs
    - Available on iOS/Android/Desktop/Web
    - Online/Offline

    Join & Write a Comment

    Suggested Solutions

    For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
    For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
    Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
    This video teaches viewers about errors in exception handling.

    731 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now