🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.jbuilder.java.swing
Article #13079

Re: problem with header in JTable

#13079
From: Steve McAtee
Date: Sun, 04 Oct 1998 00:00
105 lines
4190 bytes
I am having the same trouble.  The JBuilder books I have found explain
little how to manipulate the jdbTable (that extends from swing.JTable).  I
found a helpful example on the sun page that I have included here.  I'm
still not fixed though.  I wanted to be able to bind the table to the
queryset object Inprise provides.

import com.sun.java.swing.JTable;
import com.sun.java.swing.JScrollPane;
import com.sun.java.swing.JPanel;
import com.sun.java.swing.JFrame;
import java.awt.*;
import java.awt.event.*;

public class SimpleTableDemo extends JFrame {
    private boolean DEBUG = true;

    public SimpleTableDemo() {
        super("SimpleTableDemo");

        Object[][] data = {
            {"Mary", "Campione",
             "Snowboarding", new Integer(5), new Boolean(false)},
            {"Alison", "Huml",
             "Rowing", new Integer(3), new Boolean(true)},
            {"Kathy", "Walrath",
             "Chasing toddlers", new Integer(2), new Boolean(false)},
            {"Mark", "Andrews",
             "Speed reading", new Integer(20), new Boolean(true)},
            {"Angela", "Lih",
             "Teaching high school", new Integer(4), new Boolean(false)}
        };

        String[] columnNames = {"First Name",
                                "Last Name",
                                "Sport",
                                "# of Years",
                                "Vegetarian"};

        final JTable table = new JTable(data, columnNames);
        table.setPreferredScrollableViewportSize(new Dimension(500, 70));

        if (DEBUG) {
            table.addMouseListener(new MouseAdapter() {
                public void mouseClicked(MouseEvent e) {
                    printDebugData(table);
                }
            });
        }

        //Create the scroll pane and add the table to it.
        JScrollPane scrollPane = new JScrollPane(table);

        //Add the scroll pane to this window.
        setContentPane(scrollPane);

        addWindowListener(new WindowAdapter() {
            public void windowClosing(WindowEvent e) {
                System.exit(0);
            }
        });
    }

    private void printDebugData(JTable table) {
        int numRows = table.getRowCount();
        int numCols = table.getColumnCount();
        com.sun.java.swing.table.TableModel model = table.getModel();

        System.out.println("Value of data: ");
        for (int i=0; i < numRows; i++) {
            System.out.print("    row " + i + ":");
            for (int j=0; j < numCols; j++) {
                System.out.print("  " + model.getValueAt(i, j));
            }
            System.out.println();
        }
        System.out.println("--------------------------");
    }

    public static void main(String[] args) {
        SimpleTableDemo frame = new SimpleTableDemo();
        frame.pack();
        frame.setVisible(true);
    }
}

Anne JANSSENS wrote in message <6uq1pb$lbo7@forums.borland.com>...
>hello,
>I would like to use a JTable but with the same header for many columns like
>this :
>
>_________________________________________________
>|     header1 |           header 2             |                   header 3
>|
>|________  |_________________  |_____________________|
>|                    |                    |                   |
>|             |                  |
>|                    |                    |                   |
>|             |                  |
>
>Is it possible ??  I did not succeed in creating such a table ?
>Thanks to anyone helping me !! ( i have only 2 dukedollars to assign but it
>is very important for me )
>Anne
>
>
Technical Details
Message-ID: <6v80ge$b4o8@forums.borland.com>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <6uq1pb$lbo7@forums.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 111d45,47fc7399c59f5dda
X-Google-Attributes: gid111d45,public
From: "Steve McAtee" <srmcatee@fastrans.net>
Subject: Re: problem with header in JTable
Date: 1998/10/04
Message-ID: <6v80ge$b4o8@forums.borland.com>
X-Deja-AN: 397611013
References: <6uq1pb$lbo7@forums.borland.com>
X-MimeOLE: Produced By Microsoft MimeOLE V4.72.2106.4
Organization: Me
Newsgroups: borland.public.jbuilder.java.swing