Article View: borland.public.jbuilder.java.swing
Article #9502Re: selected cell is not showed in a JTable
From: Fam. Moreno-Lehmann
Date: Wed, 29 Mar 2000 00:00
Date: Wed, 29 Mar 2000 00:00
61 lines
2871 bytes
2871 bytes
Thank you very much for helping me, you save my life
Regards
Hilde
"John P. McGrath" wrote:
> On Tue, 28 Mar 2000 16:47:40 -0600, Fam. Moreno-Lehmann wrote:
>
> > I have a labelCellRender for a JTable, because I want to display
> > an imageIcon depending on something. Everything works fine except
> > that when I select the cell, the selectionColor does not show,
> > so you canοΏ½t see which cell is being selected.
> :
> :
> > class labelCellRenderer extends JLabel implements TableCellRenderer {
> > public labelCellRenderer() {
> > super();
> > }
> > public Component getTableCellRendererComponent( JTable table,
> > Object value, boolean isSelected, boolean hasFocus,
> > int row, int column )
> > {
> > if(value==null) { return this;}
> > if(value instanceof Detail) {
> > Detail detail = (Detail)value;
> > int level = detail.getLevel();
> > String description = detail.getDescription();
> > setText(description);
> > this.setIcon(image[level]);}
> > }
> > }
>
> Your CellRenderer is not doing anything with the "isSelected" argument,
> which is what tells the renderer that it should render the cell as
> selected. The normal thing to do here would be to set the background of
> the label to the selection color.
>
> It would also be normal to draw a focus indicator if the "hasFocus"
> argument is true. Here, the normal thing is to draw a box around the
> cell, using a dashed line.
>
> But there is no need to mess with either the selection or the focus,
> since this is already implemented in the DefaultTableCellRenderer class.
> Try the following code, instead:
>
> class labelCellRenderer extends DefaultTableCellRenderer {
> protected void setValue(Object value) {
> if (value instanceof Detail) {
> Detail detail = (Detail) value;
> int level = detail.getLevel();
> String description = detail.getDescription();
> setText(description);
> setIcon(image[level]);
> }
> }
> }
>
> --
> John P. McGrath
> <JPMcGrath@fast.net>
> <jpm@nscs.fast.net>
Technical Details
Message-ID:
<38E216A1.6850A4C0@intercable.net>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<38E1368C.A8C514BC@intercable.net> <MPG.134b8d5c4e2cd59598983c@forums.borland.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII X-Google-Thread: 111d45,e9e741b43927d24a X-Google-Attributes: gid111d45,public From: "Fam. Moreno-Lehmann" <mole@intercable.net> Subject: Re: selected cell is not showed in a JTable Date: 2000/03/29 Message-ID: <38E216A1.6850A4C0@intercable.net> X-Deja-AN: 603876172 Content-Transfer-Encoding: 8bit References: <38E1368C.A8C514BC@intercable.net> <MPG.134b8d5c4e2cd59598983c@forums.borland.com> X-Accept-Language: en Content-Type: text/plain; charset=iso-8859-1 X-Trace: 29 Mar 2000 06:32:32 -0800, 207.248.41.120 MIME-Version: 1.0 Newsgroups: borland.public.jbuilder.java.swing