🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: JTable, Srolling in applets, custom cell rederer, changing colors of some table rows

#12859
From: Anne JANSSENS
Date: Tue, 27 Oct 1998 00:00
172 lines
7861 bytes
Message en plusieurs parties et au format MIME.

------=_NextPart_000_0077_01BE01B5.582B65A0
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

Here are some ideas to solve your problem, hope it would help !
Anne
=20
Multiligne Text :
By default, the cell renderer of the JTableHeader is a JLabel component, =
that means
that you can not have multiligne in a header.
To change the renderer of the JTable :
mytable.getColumnModel().getColumn(num_col).setHeaderRenderer(new =
Renderer());
I think you can define a new Render for each column header that would be =
based on a multiligne component
such as TextComponent=20
=20
ex : public class Renderer extends JTextComponent implements =
TableCellRenderer
{    public Renderer
     {  setOpaque(true);
        setForeground(UIManager.getColor("TableHeader.foreground"));
        setBackground(UIManager.getColor("TableHeader.background"));
        -- you may want to change the paint in the column=20
        -- if you want more detail, you can ask me
       setBorder(new myBorder()
       {  =20
       });
    =20
    }
=20
   public Component getTableCellRendererComponent(JTable table,
                                                  Object value,
                                                  boolean isSelected,
                                                  boolean hasFocus,
                                                  int row,
                                                  int column)
   { setFont(table.getFont());
     setText(value.toString());
     return this ;
  }

}
=20
What I have implemented is multicolumn header, by modifying the border =
of the column you can find
the example in response of one of my question : problem with header in =
JTable dated 29-09-98!
=20
=20

Rows with different colors :
No problem to fix the color to a kind of row, if you have a columnModel =
for your table
you have to get the columnModel of your table, then the column you want =
to color, on which=20
you set a CellRenderer which color your cell
mytable.getColumnModel().getColumn(num_col).getCellRenderer().setBackgrou=
nd(mycolor)=20
=20

MOST IMPORTANT ! column headers don't repaint>
To force your column header to repaint try this :
mytable.getTableHeader().resizeAndRepaint();


------=_NextPart_000_0077_01BE01B5.582B65A0
Content-Type: text/html;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

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

<META content=3Dtext/html;charset=3Diso-8859-1 =
http-equiv=3DContent-Type>
<META content=3D'"MSHTML 4.72.2106.6"' name=3DGENERATOR>
</HEAD>
<BODY>
<DIV><FONT size=3D2>Here are some ideas to solve your problem, hope it =
would help=20
!<BR>Anne<BR>&nbsp;<BR>Multiligne Text :<BR>By default, the cell =
renderer of the=20
JTableHeader is a JLabel component, that means<BR>that you can not have=20
multiligne in a header.<BR>To change the renderer of the JTable=20
:<BR>mytable.getColumnModel().getColumn(num_col).setHeaderRenderer(new=20
Renderer());<BR>I think you can define a new Render for each column =
header that=20
would be based on a multiligne component<BR>such as TextComponent=20
<BR>&nbsp;<BR>ex : public class Renderer extends JTextComponent =
implements=20
TableCellRenderer<BR>{&nbsp;&nbsp;&nbsp; public=20
Renderer<BR>&nbsp;&nbsp;&nbsp;&nbsp; {&nbsp;=20
setOpaque(true);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
setForeground(UIManager.getColor(&quot;TableHeader.foreground&quot;));<BR=
>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
setBackground(UIManager.getColor(&quot;TableHeader.background&quot;));<BR=
>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
-- you may want to change the paint in the column=20
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; -- if you want more =
detail, you=20
can ask me<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; setBorder(new=20
myBorder()<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {&nbsp;&nbsp;=20
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; });<BR>&nbsp;&nbsp;&nbsp;&nbsp; =

<BR>&nbsp;&nbsp;&nbsp; }<BR>&nbsp;<BR>&nbsp;&nbsp; public Component=20
get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bsp;&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;&n=
bsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb=
sp;&nbsp;&nbsp;=20
int=20
row,<BR>&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;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&=
nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n=
bsp;&nbsp;=20
int column)<BR>&nbsp;&nbsp; {=20
setFont(table.getFont());<BR>&nbsp;&nbsp;&nbsp;&nbsp;=20
setText(value.toString());<BR>&nbsp;&nbsp;&nbsp;&nbsp; return this =
;<BR>&nbsp;=20
}</FONT></DIV>
<DIV><FONT size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2>}<BR>&nbsp;<BR>What I have implemented is =
multicolumn header,=20
by modifying the border of the column you can find<BR>the example in =
response of=20
one of my question : problem with header in JTable dated=20
29-09-98!<BR>&nbsp;<BR>&nbsp;</FONT></DIV>
<DIV><FONT size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2>Rows with different colors :<BR>No problem to fix =
the color to=20
a kind of row, if you have a columnModel for your table<BR>you have to =
get the=20
columnModel of your table, then the column you want to color, on which =
<BR>you=20
set a CellRenderer which color your=20
cell<BR>mytable.getColumnModel().getColumn(num_col).getCellRenderer().set=
Background(mycolor)=20
<BR>&nbsp;</FONT></DIV>
<DIV><FONT size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2>MOST IMPORTANT ! column headers don't =
repaint&gt;<BR>To force=20
your column header to repaint try this=20
:<BR>mytable.getTableHeader().resizeAndRepaint();</FONT></DIV></BODY></HT=
ML>

------=_NextPart_000_0077_01BE01B5.582B65A0--
Technical Details
Message-ID: <714hb6$9ou8@forums.borland.com>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <3630C022.3F2DC411@hackenberg.de>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 111d45,121728c027f038c9
X-Google-Attributes: gid111d45,public
From: "Anne JANSSENS" <recherche@generix.fr>
Subject: Re: JTable, Srolling in applets, custom cell rederer, changing colors of some table rows
Date: 1998/10/27
Message-ID: <714hb6$9ou8@forums.borland.com>
X-Deja-AN: 405545883
References: <3630C022.3F2DC411@hackenberg.de>
Content-Type: multipart/alternative; boundary="----=_NextPart_000_0077_01BE01B5.582B65A0"
X-MimeOLE: Produced By Microsoft MimeOLE V4.72.2106.4
Organization: Another Netscape Collabra Server User
Mime-Version: 1.0
Newsgroups: borland.public.jbuilder.java.swing