🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: Colunn Headers for Jtable

#13081
From: Steve McAtee
Date: Sun, 04 Oct 1998 00:00
198 lines
8131 bytes
This is a multi-part message in MIME format.

------=_NextPart_000_000E_01BDEFC4.B7E7EB60
Content-Type: text/plain;
	charset="koi8-r"
Content-Transfer-Encoding: quoted-printable

I appreciate your example but let me clarify a little more.  I am trying =
to put column headers on Borlands jdbTable class.  I've placed a =
jdbTable control on my design page and have attached it to a =
QueryDataSet.  The table shows the raw data but does not display any =
column headers.  How do I now put column headers on the table???

Please advise.
    Vladimir Olenin wrote in message =
<3617F416.1280D3F7@collegemail.com>...
    Well, actually it's pretty simple. As usual in Swing u just need to
    override some Model class to customize a component. So, here is an
    example:
   =20
    =
/////////////////////////////////////////////////////////////////////////=
///////
      class CustomTableModel extends AbstractTableModel{
        Object[][] data;
        String[] columnNames =3D {"Property", "Value"};
   =20
        CustomTableModel(String[] prop){              // The constructor
    might be empty as well,
          data =3D new Object[prop.length][2];          // if i'm not =
mistaken
          for(int row =3D 0; row < prop.length; row++)
            setValueAt(prop[row], row, 0);
        }
   =20
        public int getColumnCount(){
          return columnNames.length;
        }
   =20
        public int getRowCount(){
          return data.length;
        }
   =20
        public String getColumnName(int col){
          return columnNames[col];
        }
    /*
        public Class getColumnClass(int c){
          return getValueAt(0, c).getClass();
        }
    */
        public boolean isCellEditable(int row, int col){
          return false;
        }
   =20
        public void setValueAt(Object value, int row, int col){
          data[row][col] =3D value;
        }
   =20
        public Object getValueAt(int row, int col){
          return data[row][col];
        }
   =20
      }
    =
/////////////////////////////////////////////////////////////////////////=
///////
    To construct JTable itself, type this string:
    JTable table =3D new JTable(serverModel); //serverModel is an =
instance of
    CustomTableModel
   =20
   =20
    Just want to add another thing: read through JavaSoft Swing =
tutorial!
    U'll find it to be VERY useful. I've attached the page of this =
tutorial
    concerning the problem of customizing JTable components. All the =
best,
                                              Vladimir Olenin
   =20
   =20
    Steve McAtee wrote:
    >=20
    > I'm attempting to do this and having little luck.  Does anyone =
have example
    > code of how to set a header for a column on the Jtable class.
    >=20
    > Thanks

------=_NextPart_000_000E_01BDEFC4.B7E7EB60
Content-Type: text/html;
	charset="koi8-r"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD W3 HTML//EN">
<HTML>
<HEAD>

<META content=3Dtext/html;charset=3Dkoi8-r http-equiv=3DContent-Type>
<META content=3D'"MSHTML 4.72.2106.6"' name=3DGENERATOR>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT color=3D#000000 size=3D2>I appreciate your example but let me =
clarify a=20
little more.&nbsp; I am trying to put column headers on Borlands =
jdbTable=20
class.&nbsp; I've placed a jdbTable control on my design page and have =
attached=20
it to a QueryDataSet.&nbsp; The table shows the raw data but does not =
display=20
any column headers.&nbsp; How do I now put column headers on the=20
table???</FONT></DIV>
<DIV><FONT color=3D#000000 size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2>Please advise.</FONT></DIV>
<BLOCKQUOTE=20
style=3D"BORDER-LEFT: #000000 solid 2px; MARGIN-LEFT: 5px; PADDING-LEFT: =
5px">
    <DIV>Vladimir Olenin<KEENONJAVA@COLLEGEMAIL.COM> wrote in message =
&lt;<A=20
    =
href=3D"mailto:3617F416.1280D3F7@collegemail.com">3617F416.1280D3F7@colle=
gemail.com</A>&gt;...</DIV>Well,=20
    actually it's pretty simple. As usual in Swing u just need =
to<BR>override=20
    some Model class to customize a component. So, here is=20
    =
an<BR>example:<BR><BR>///////////////////////////////////////////////////=
/////////////////////////////<BR>&nbsp;=20
    class CustomTableModel extends =
AbstractTableModel{<BR>&nbsp;&nbsp;&nbsp;=20
    Object[][] data;<BR>&nbsp;&nbsp;&nbsp; String[] columnNames =3D=20
    {&quot;Property&quot;, &quot;Value&quot;};<BR><BR>&nbsp;&nbsp;&nbsp; =

    CustomTableModel(String[]=20
    =
prop){&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&=
nbsp;&nbsp;=20
    // The constructor<BR>might be empty as=20
    well,<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; data =3D new=20
    =
Object[prop.length][2];&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n=
bsp;=20
    // if i'm not mistaken<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for(int row =
=3D 0;=20
    row &lt; prop.length; =
row++)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
    setValueAt(prop[row], row, 0);<BR>&nbsp;&nbsp;&nbsp;=20
    }<BR><BR>&nbsp;&nbsp;&nbsp; public int=20
    getColumnCount(){<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return=20
    columnNames.length;<BR>&nbsp;&nbsp;&nbsp; =
}<BR><BR>&nbsp;&nbsp;&nbsp; public=20
    int getRowCount(){<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return=20
    data.length;<BR>&nbsp;&nbsp;&nbsp; }<BR><BR>&nbsp;&nbsp;&nbsp; =
public String=20
    getColumnName(int col){<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return=20
    columnNames[col];<BR>&nbsp;&nbsp;&nbsp; =
}<BR>/*<BR>&nbsp;&nbsp;&nbsp; public=20
    Class getColumnClass(int c){<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
return=20
    getValueAt(0, c).getClass();<BR>&nbsp;&nbsp;&nbsp;=20
    }<BR>*/<BR>&nbsp;&nbsp;&nbsp; public boolean isCellEditable(int row, =
int=20
    col){<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return =
false;<BR>&nbsp;&nbsp;&nbsp;=20
    }<BR><BR>&nbsp;&nbsp;&nbsp; public void setValueAt(Object value, int =
row,=20
    int col){<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; data[row][col] =3D=20
    value;<BR>&nbsp;&nbsp;&nbsp; }<BR><BR>&nbsp;&nbsp;&nbsp; public =
Object=20
    getValueAt(int row, int col){<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
return=20
    data[row][col];<BR>&nbsp;&nbsp;&nbsp; }<BR><BR>&nbsp;=20
    =
}<BR>////////////////////////////////////////////////////////////////////=
////////////<BR>To=20
    construct JTable itself, type this string:<BR>JTable table =3D new=20
    JTable(serverModel); //serverModel is an instance=20
    of<BR>CustomTableModel<BR><BR><BR>Just want to add another thing: =
read=20
    through JavaSoft Swing tutorial!<BR>U'll find it to be VERY useful. =
I've=20
    attached the page of this tutorial<BR>concerning the problem of =
customizing=20
    JTable components. All the=20
    =
best,<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp=
;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
    Vladimir Olenin<BR><BR><BR>Steve McAtee wrote:<BR>&gt; <BR>&gt; I'm=20
    attempting to do this and having little luck.&nbsp; Does anyone have =

    example<BR>&gt; code of how to set a header for a column on the =
Jtable=20
    class.<BR>&gt; <BR>&gt; Thanks</BLOCKQUOTE></BODY></HTML>

------=_NextPart_000_000E_01BDEFC4.B7E7EB60--
Technical Details
Message-ID: <6v8vsl$csr12@forums.borland.com>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <6v68tb$9ui7@forums.borland.com> <3617F416.1280D3F7@collegemail.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 111d45,bf2742f8dac80943
X-Google-Attributes: gid111d45,public
From: "Steve McAtee" <srmcatee@fastrans.net>
Subject: Re: Colunn Headers for Jtable
Date: 1998/10/04
Message-ID: <6v8vsl$csr12@forums.borland.com>
X-Deja-AN: 397739083
References: <6v68tb$9ui7@forums.borland.com> <3617F416.1280D3F7@collegemail.com>
Content-Type: multipart/alternative; boundary="----=_NextPart_000_000E_01BDEFC4.B7E7EB60"
X-MimeOLE: Produced By Microsoft MimeOLE V4.72.2106.4
Organization: Me
Mime-Version: 1.0
Newsgroups: borland.public.jbuilder.java.swing