 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Adrian Pitulac Guest
|
Posted: Tue Oct 26, 2004 1:23 am Post subject: Need Help writing a custom Cell Renderer with DBCellRenderer |
|
|
Hello,
I'm trying to change some cell values for a TableDataSet at loading time. I
want to change some specific date values "1970/01/01" into a text like "N/A"
or to leave that table cell empty. I have tried to work with DBCellRenderer
but i got some "cannot resolve symbol " errors.... pointing to
JdbTable.DBCellRenderer class...
Please help me with some advices.. or any other way of dealing with my
problem it's very URGENT... Is there any other way of solving my problem
else then that with JdbTable.DBCellRenderer?
This is the example from the Jbuilder Manuals:
import java.awt.*;
import javax.swing.*;
import com.borland.dbswing.*;
public class NegativeNumberRenderer extends JdbTable.DBCellRenderer {
public NegativeNumberRenderer(JdbTable jdbTable) {
jdbTable.super();
}
public Component getTableCellRendererComponent(JTable table, Object
value,
boolean isSelected, boolean hasFocus, int row, int column) {
super.getTableCellRendererComponent(table,value, isSelected, hasFocus,
row, column);
if (value != null) {
try {
// Compare numeric value of string to zero. This assumes that a
negative
// value has a leading minus sign, so only handles simple numeric
formats
if (Double.parseDouble((String) value) < 0.0d)
super.setForeground(Color.red);
}
// Use the default foreground if we can't get a number from the
string
catch (NumberFormatException nfe) {
}
}
return this;
}
}
Thanks....
|
|
| Back to top |
|
 |
Steve Burling Guest
|
Posted: Wed Nov 10, 2004 12:47 am Post subject: Re: Need Help writing a custom Cell Renderer with DBCellRend |
|
|
In article <417da6f4$1 (AT) newsgroups (DOT) borland.com>,
"Adrian Pitulac" <apitulac (AT) pcnet (DOT) ro> wrote:
| Quote: | I'm trying to change some cell values for a TableDataSet at loading time. I
want to change some specific date values "1970/01/01" into a text like "N/A"
or to leave that table cell empty. I have tried to work with DBCellRenderer
but i got some "cannot resolve symbol " errors.... pointing to
JdbTable.DBCellRenderer class...
Please help me with some advices.. or any other way of dealing with my
problem it's very URGENT... Is there any other way of solving my problem
else then that with JdbTable.DBCellRenderer?
|
Did you ever get a solution to your problem? I'm in the same boat...
I'm a newbie to JBuilder and the dbswing classes, and a relative newbie
to Java as well, so I have a big learning curve in front of me. But it
doesn't seem like what I'm trying to do should be as hard as it is
proving, and I've got to believe that I'm missing something obvious.
Here's what I'm trying to do: I've got an application with two
tableScrollPanes, each of which contains a jdbTable. Each jdbTable, in
turn, has an associated QueryDataSet. What I'm trying to figure out is
how to render *some* of the rows of the table differently. It could be,
say, that the text is italic, or the background color could be
different. Something. But I can't seem to get over the basic hump;
I've defined a class that extends DefaultTableCellRenderer, and
instantiated it as the DefaultCellRenderer for one of the jdbTables, but
its getTableCellRendererComponent method never gets invoked.
So I, too, thought I'd try the method described in the JBuilder jdbTable
documentation, but ran into the same problems about undefined symbols as
the original poster.
If anyone has a relatively simple example of doing this that they'd be
willing to share, I'd be very grateful. Heck, if you're anywhere near
me (Ann Arbor, MI), I'll buy you a beer or two. And if you're anywhere
near Madison, WI, I'll be in the area a few days before (US)
Thanksgiving, so I'd buy you a beer there .
--
Steve Burling <mailto:srb (AT) umich (DOT) edu>
University of Michigan, ICPSR Voice: +1 734 615.3779
330 Packard Street FAX: +1 734 647.8700
Ann Arbor, MI 48104-2910
|
|
| Back to top |
|
 |
David Sykes Guest
|
Posted: Wed Nov 10, 2004 10:01 am Post subject: Re: Need Help writing a custom Cell Renderer with DBCellRend |
|
|
We have successfully implemented a custom cell renderer for use in a
JdbTable. It looks something like this:
class MyRenderer extends TableFastStringRenderer {
public Component getTableCellRendererComponent(JTable table,
Object value,
boolean isSelected,
boolean hasFocus,
int row,
int column) {
Component renderer =
super.getTableCellRendererComponent(table,value,isSelected,hasFocus,row,colu
mn);
JdbTable dbTable = (JdbTable) table;
if (dbTable.getDataSet().getString("STATUS").equals("invalid")) {
setBackground(Color.red);
}
else if (dbTable.getDataSet().isNull("DATE_FIELD")) {
setValue("N/A");
}
else if (dbTable.getDataSet().getString("IS_URGENT").equals("yes")) {
setFont(myItalicFont);
}
}
}
*NOTE: we only change the background colour in our renderer, but I am
confident that the font and value changes would also work as I have shown
here.
The TableFastStringRenderer is the default class used for rendering cells in
JdbTables. At least it was in earlier versions of JBuilder. I have not
checked this in JB2005, but our custom renderer works unchanged.
To install the custom renderer, we subclass JdbTable, and override the
(protected) getDefaultCellRenderer() method to return an instance of the
custom renderer. As follows:
class MyDbTable extends JdbTable {
protected TableCellRenderer getDefaultCellRenderer(Column dataSetColumn) {
if (one of the columns I want the custom renderer for) {
return new MyRenderer();
}
else {
return super.getDefaultCellRenderer(dataSetColumn);
}
}
}
There is probably another way to install the custom renderer for your
columns, but the way I have shown here works for us.
Hope this helps you,
David Sykes
"Steve Burling" <srb (AT) umich (DOT) edu> wrote
| Quote: | In article <417da6f4$1 (AT) newsgroups (DOT) borland.com>,
"Adrian Pitulac" <apitulac (AT) pcnet (DOT) ro> wrote:
I'm trying to change some cell values for a TableDataSet at loading
time. I
want to change some specific date values "1970/01/01" into a text like
"N/A"
or to leave that table cell empty. I have tried to work with
DBCellRenderer
but i got some "cannot resolve symbol " errors.... pointing to
JdbTable.DBCellRenderer class...
Please help me with some advices.. or any other way of dealing with my
problem it's very URGENT... Is there any other way of solving my problem
else then that with JdbTable.DBCellRenderer?
Did you ever get a solution to your problem? I'm in the same boat...
I'm a newbie to JBuilder and the dbswing classes, and a relative newbie
to Java as well, so I have a big learning curve in front of me. But it
doesn't seem like what I'm trying to do should be as hard as it is
proving, and I've got to believe that I'm missing something obvious.
Here's what I'm trying to do: I've got an application with two
tableScrollPanes, each of which contains a jdbTable. Each jdbTable, in
turn, has an associated QueryDataSet. What I'm trying to figure out is
how to render *some* of the rows of the table differently. It could be,
say, that the text is italic, or the background color could be
different. Something. But I can't seem to get over the basic hump;
I've defined a class that extends DefaultTableCellRenderer, and
instantiated it as the DefaultCellRenderer for one of the jdbTables, but
its getTableCellRendererComponent method never gets invoked.
So I, too, thought I'd try the method described in the JBuilder jdbTable
documentation, but ran into the same problems about undefined symbols as
the original poster.
If anyone has a relatively simple example of doing this that they'd be
willing to share, I'd be very grateful. Heck, if you're anywhere near
me (Ann Arbor, MI), I'll buy you a beer or two. And if you're anywhere
near Madison, WI, I'll be in the area a few days before (US)
Thanksgiving, so I'd buy you a beer there .
--
Steve Burling
University of Michigan, ICPSR Voice: +1 734 615.3779
330 Packard Street FAX: +1 734 647.8700
Ann Arbor, MI 48104-2910
|
|
|
| Back to top |
|
 |
Adrian Pitulac Guest
|
Posted: Sat Nov 20, 2004 12:43 am Post subject: Re: Need Help writing a custom Cell Renderer with DBCellRend |
|
|
Sure. No answer till now. Anyway i have managed after some time to find a
solution:
static class Painter implements ColumnPaintListener {
public Painter() { super();}
public void editing(DataSet dataSet, Column column, CustomPaintSite
paintSite){}
public void painting(DataSet dataSet, Column column, int row, Variant
value, CustomPaintSite paintSite){
if(value.getDate().toString().matches("1970-01-01")){value.setDate(null);}
}
}
And in the initialization code (jbInit() usually) put:
Column col_15 = jdbTable1.getDataSet().getColumn(15);
col_15.addColumnPaintListener(new Painter());
This should do it. I think that this is a easier way of doing the "job" than
the way David Sykes showed you. I have tried also that solution but it
seemed to me that it was a little harder to implement.
If you need any other help tell me and i'll gladly help you.
Adrian
"Steve Burling" <srb (AT) umich (DOT) edu> wrote
| Quote: | In article <417da6f4$1 (AT) newsgroups (DOT) borland.com>,
"Adrian Pitulac" <apitulac (AT) pcnet (DOT) ro> wrote:
I'm trying to change some cell values for a TableDataSet at loading
time. I
want to change some specific date values "1970/01/01" into a text like
"N/A"
or to leave that table cell empty. I have tried to work with
DBCellRenderer
but i got some "cannot resolve symbol " errors.... pointing to
JdbTable.DBCellRenderer class...
Please help me with some advices.. or any other way of dealing with my
problem it's very URGENT... Is there any other way of solving my problem
else then that with JdbTable.DBCellRenderer?
Did you ever get a solution to your problem? I'm in the same boat...
I'm a newbie to JBuilder and the dbswing classes, and a relative newbie
to Java as well, so I have a big learning curve in front of me. But it
doesn't seem like what I'm trying to do should be as hard as it is
proving, and I've got to believe that I'm missing something obvious.
Here's what I'm trying to do: I've got an application with two
tableScrollPanes, each of which contains a jdbTable. Each jdbTable, in
turn, has an associated QueryDataSet. What I'm trying to figure out is
how to render *some* of the rows of the table differently. It could be,
say, that the text is italic, or the background color could be
different. Something. But I can't seem to get over the basic hump;
I've defined a class that extends DefaultTableCellRenderer, and
instantiated it as the DefaultCellRenderer for one of the jdbTables, but
its getTableCellRendererComponent method never gets invoked.
So I, too, thought I'd try the method described in the JBuilder jdbTable
documentation, but ran into the same problems about undefined symbols as
the original poster.
If anyone has a relatively simple example of doing this that they'd be
willing to share, I'd be very grateful. Heck, if you're anywhere near
me (Ann Arbor, MI), I'll buy you a beer or two. And if you're anywhere
near Madison, WI, I'll be in the area a few days before (US)
Thanksgiving, so I'd buy you a beer there .
--
Steve Burling
University of Michigan, ICPSR Voice: +1 734 615.3779
330 Packard Street FAX: +1 734 647.8700
Ann Arbor, MI 48104-2910
|
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|