Article View: borland.public.jbuilder.java.swing
Article #13081Re: Colunn Headers for Jtable
From: Steve McAtee
Date: Sun, 04 Oct 1998 00:00
Date: Sun, 04 Oct 1998 00:00
198 lines
8131 bytes
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. I am trying to put column headers on Borlands =
jdbTable=20
class. I've placed a jdbTable control on my design page and have =
attached=20
it to a QueryDataSet. The table shows the raw data but does not =
display=20
any column headers. How do I now put column headers on the=20
table???</FONT></DIV>
<DIV><FONT color=3D#000000 size=3D2></FONT> </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 =
<<A=20
=
href=3D"mailto:3617F416.1280D3F7@collegemail.com">3617F416.1280D3F7@colle=
gemail.com</A>>...</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> =20
class CustomTableModel extends =
AbstractTableModel{<BR> =20
Object[][] data;<BR> String[] columnNames =3D=20
{"Property", "Value"};<BR><BR> =
CustomTableModel(String[]=20
=
prop){ &=
nbsp; =20
// The constructor<BR>might be empty as=20
well,<BR> data =3D new=20
=
Object[prop.length][2]; &n=
bsp;=20
// if i'm not mistaken<BR> for(int row =
=3D 0;=20
row < prop.length; =
row++)<BR> =20
setValueAt(prop[row], row, 0);<BR> =20
}<BR><BR> public int=20
getColumnCount(){<BR> return=20
columnNames.length;<BR> =
}<BR><BR> public=20
int getRowCount(){<BR> return=20
data.length;<BR> }<BR><BR> =
public String=20
getColumnName(int col){<BR> return=20
columnNames[col];<BR> =
}<BR>/*<BR> public=20
Class getColumnClass(int c){<BR> =
return=20
getValueAt(0, c).getClass();<BR> =20
}<BR>*/<BR> public boolean isCellEditable(int row, =
int=20
col){<BR> return =
false;<BR> =20
}<BR><BR> public void setValueAt(Object value, int =
row,=20
int col){<BR> data[row][col] =3D=20
value;<BR> }<BR><BR> public =
Object=20
getValueAt(int row, int col){<BR> =
return=20
data[row][col];<BR> }<BR><BR> =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> &nbs=
p;  =
; =
=20
Vladimir Olenin<BR><BR><BR>Steve McAtee wrote:<BR>> <BR>> I'm=20
attempting to do this and having little luck. Does anyone have =
example<BR>> code of how to set a header for a column on the =
Jtable=20
class.<BR>> <BR>> 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-mailReferences:
<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