JTable

R

rainny

Hi ..all

I have some question about the jtable data. When I select the data
from database and display into table, there are 4 columns which are
a.time, b.time, a, b.

Does anybody have any idea to make the a.time and b.time column into
one column??


Thanks for reply..
 
M

Michael Rauscher

rainny said:
Hi ..all

I have some question about the jtable data. When I select the data
from database and display into table, there are 4 columns which are
a.time, b.time, a, b.

Does anybody have any idea to make the a.time and b.time column into
one column??

There are a lot of possibilities:

a) modify your query

E. g. in Oracle-like syntax:
SELECT to_char(a.time, 'dd.mm.rr') || ' - ' ||
to_char(b.time, 'dd.mm.rr') AS period
FROM a, b ...

b) if you insert the data into a table model,
insert the desired values

DateFormat df = ...;
Date d1 = rs.getDate(1);
Date d2 = rs.getDate(2);
String colValue = String.format("%s - %s",
df.format(d1), df.format(d2));
// insert colValue into the table model

c) if you have your own TableModel, let getValueAt
return the desired value

public Object getValueAt(int row, int col) {
// assume a DateFormat df,
// extract Date d1, Date d2 from the data model
if ( col == 1 ) {
return String.format("%s - %s",
df.format(d1), df.format(d2));
}
//...
}

d) if you have a TableModel that you don't want to
(or can't) modify you might want to use a decorator.

e) ...

HTH
Michael
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,982
Messages
2,570,190
Members
46,738
Latest member
TiffinyHol

Latest Threads

Top