BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

JdbTable HeaderRenderer Problem

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> JBuilder DB Swing
View previous topic :: View next topic  
Author Message
Christa Schneider
Guest





PostPosted: Thu Apr 20, 2006 3:04 pm    Post subject: JdbTable HeaderRenderer Problem Reply with quote



Hi,

I'am trying to change the Header of a JdbTable. If I do the same with a
JTable it works fine.
Can anybody help me?

Here is the example:
....
TableCellRenderer rd = new CSCheckBoxHeader();
table.getColumnModel().getColumn(1).setHeaderRenderer(rd);
....

public class CSCheckBoxHeader extends JCheckBox implements TableCellRenderer
{

public CSCheckBoxHeader() {
super();
}

public Component getTableCellRendererComponent(JTable table, Object value,
boolean isSelected, boolean
hasfocus,
int row, int col) {
....
//header.addMouseListener(this);
return this;
}

Thanks...
Back to top
Kevin Dean [TeamB]
Guest





PostPosted: Thu Apr 20, 2006 11:04 pm    Post subject: Re: JdbTable HeaderRenderer Problem Reply with quote



Christa Schneider wrote:

Quote:
Hi,

I'am trying to change the Header of a JdbTable. If I do the same with a
JTable it works fine.
Can anybody help me?

Here is the example:
...
TableCellRenderer rd = new CSCheckBoxHeader();
table.getColumnModel().getColumn(1).setHeaderRenderer(rd);
...

public class CSCheckBoxHeader extends JCheckBox implements
TableCellRenderer {

public CSCheckBoxHeader() {
super();
}

public Component getTableCellRendererComponent(JTable table, Object value,
boolean isSelected, boolean hasfocus,
int row, int col) {
...
//header.addMouseListener(this);
return this;
}


The JdbTable gets the column header names from the Column objects in the
data set. Use the Column.setCaption() method.

--
Kevin Dean [TeamB]
Dolphin Data Development Ltd.
http://www.datadevelopment.com/

NEW WHITEPAPERS
Team Development with JBuilder and Borland Enterprise Server
Securing Borland Enterprise Server
http://www.datadevelopment.com/papers/index.html

Please see Borland's newsgroup guidelines at
http://info.borland.com/newsgroups/guide.html
Back to top
Christa Schneider
Guest





PostPosted: Fri Apr 21, 2006 1:04 pm    Post subject: Re: JdbTable HeaderRenderer Problem Reply with quote



Hi,
thanks for the answer, but this is not my problem.
I will write a new HeaderRenderer with a JCheckbox. The example with the new
Renderer works with JTable but not with JdbTable and I don't know why.
Maybe anyone have had the same problem...
Thanks
Christa



"Kevin Dean [TeamB]" <NkOdSePaAnM (AT) datadevelopment (DOT) com> schrieb im
Newsbeitrag news:xn0el7k53kzzy002-kdean (AT) www (DOT) teamb.com...
Quote:
Christa Schneider wrote:

Hi,

I'am trying to change the Header of a JdbTable. If I do the same with a
JTable it works fine.
Can anybody help me?

Here is the example:
...
TableCellRenderer rd = new CSCheckBoxHeader();
table.getColumnModel().getColumn(1).setHeaderRenderer(rd);
...

public class CSCheckBoxHeader extends JCheckBox implements
TableCellRenderer {

public CSCheckBoxHeader() {
super();
}

public Component getTableCellRendererComponent(JTable table, Object
value,
boolean isSelected,
boolean hasfocus,
int row, int col) {
...
//header.addMouseListener(this);
return this;
}


The JdbTable gets the column header names from the Column objects in the
data set. Use the Column.setCaption() method.

--
Kevin Dean [TeamB]
Dolphin Data Development Ltd.
http://www.datadevelopment.com/

NEW WHITEPAPERS
Team Development with JBuilder and Borland Enterprise Server
Securing Borland Enterprise Server
http://www.datadevelopment.com/papers/index.html

Please see Borland's newsgroup guidelines at
http://info.borland.com/newsgroups/guide.html
Back to top
Olaf Raether
Guest





PostPosted: Fri Apr 21, 2006 2:03 pm    Post subject: Re: JdbTable HeaderRenderer Problem Reply with quote

From my point of view you have to override the method

public void createDefaultColumnsFromModel()

from JDbTable. In this method everything happens.I hope you have
enterprise version, and you are able to take a look at the source of
JdbTable. There you find the "setHeaderRenderer" method.

Then you have a write a method that looks similar like this.

public void createDefaultColumnsFromModel() {
super.createDefaultColumnsFromModel();
Object identifier=null;
for (int i=0;i<this.getDataSet().getColumnCount();i++) {
identifier = this.getDataSet().getColumn(i).getColumnName();
getColumn(identifier).setHeaderRenderer(new YourRenderer());
}
}

This code is not complete. But i think this one possible solution and
give you a hint.

Hope this helps.


Olaf Raether



Christa Schneider wrote:
Quote:
Hi,
thanks for the answer, but this is not my problem.
I will write a new HeaderRenderer with a JCheckbox. The example with the new
Renderer works with JTable but not with JdbTable and I don't know why.
Maybe anyone have had the same problem...
Thanks
Christa



"Kevin Dean [TeamB]" <NkOdSePaAnM (AT) datadevelopment (DOT) com> schrieb im
Newsbeitrag news:xn0el7k53kzzy002-kdean (AT) www (DOT) teamb.com...
Christa Schneider wrote:

Hi,

I'am trying to change the Header of a JdbTable. If I do the same with a
JTable it works fine.
Can anybody help me?

Here is the example:
...
TableCellRenderer rd = new CSCheckBoxHeader();
table.getColumnModel().getColumn(1).setHeaderRenderer(rd);
...

public class CSCheckBoxHeader extends JCheckBox implements
TableCellRenderer {

public CSCheckBoxHeader() {
super();
}

public Component getTableCellRendererComponent(JTable table, Object
value,
boolean isSelected,
boolean hasfocus,
int row, int col) {
...
//header.addMouseListener(this);
return this;
}

The JdbTable gets the column header names from the Column objects in the
data set. Use the Column.setCaption() method.

--
Kevin Dean [TeamB]
Dolphin Data Development Ltd.
http://www.datadevelopment.com/

NEW WHITEPAPERS
Team Development with JBuilder and Borland Enterprise Server
Securing Borland Enterprise Server
http://www.datadevelopment.com/papers/index.html

Please see Borland's newsgroup guidelines at
http://info.borland.com/newsgroups/guide.html



Back to top
Christa Schneider
Guest





PostPosted: Tue May 16, 2006 2:15 pm    Post subject: Re: JdbTable HeaderRenderer Problem Reply with quote

Hallo,

thank you very much for this info, it works!

Christa Schneider

Here the Sourcecode for all they have the same problems:

public class CSCheckBoxHeader
extends JPanel
implements TableCellRenderer {
JCheckBox chkSel = new JCheckBox();
JButton cmdTitle = new JButton();
Object obj;

public CSCheckBoxHeader(Object obj) {
super();
this.obj = obj;
cmdTitle.setMargin(new Insets(1, 1, 1, 1));
setLayout(new BorderLayout(0, 0));
add(chkSel, BorderLayout.WEST);
add(cmdTitle, BorderLayout.CENTER);
}

public CSCheckBoxHeader(Object obj, String fontName, int attr, int size) {
super();
this.obj = obj;
setLayout(new BorderLayout(0, 0));
cmdTitle.setMargin(new Insets(1, 1, 1, 1));
cmdTitle.setFont(new Font(fontName, attr, size));
add(chkSel, BorderLayout.WEST);
add(cmdTitle, BorderLayout.CENTER);

}

public Component getTableCellRendererComponent(JTable table, Object value,
boolean isSelected,
boolean hasfocus,
int row, int col) {
cmdTitle.setText( (String) obj);
return this;
}

public JCheckBox getCheckBox() {
return chkSel;
}

public void setSelected(boolean wert) {
chkSel.setSelected(wert);
}

public boolean isSelected() {
return chkSel.isSelected();
}
}

public class CSJdbTable
extends JdbTable
implements MouseListener {
Vector v = new Vector(); // merkt sich die HeaderRenderer
boolean first = true; //Renderer nur beim ersten Mal aufbauen
public CSJdbTable() {
}

public CSJdbTable(Object rows[][], Object header[]) {
super(rows, header);
}

/*
overriding function in JdbTable
da die Funktion bei jedem click auf den Header ausgelöst wird,
muss hier abgefragt werden, ob bereits ein HeaderRenderer besteht,
damit dieser nicht jedesmal neu angelegt wird
*/

public void createDefaultColumnsFromModel() {
Object identifier = null;
super.createDefaultColumnsFromModel();

if (this.getDataSet() != null) {

for (int i = 0; i < this.getDataSet().getColumnCount(); i++) {
try {
identifier = this.getDataSet().getColumn(i).getColumnName();
String caption = this.getDataSet().getColumn(i).getCaption();
if (first && identifier != null &&
this.getDataSet().getColumn(i).isHidden() == false) {
CSCheckBoxHeader chk = new
CSCheckBoxHeader(caption,"Dialog",Font.PLAIN,10);
v.add(chk);
getColumn(identifier).setHeaderRenderer(chk);
}
else {
getColumn(identifier).setHeaderRenderer( (CSCheckBoxHeader)
v.get(i));
}
}

catch (IllegalArgumentException ex) {
}

}

if (first) {
first = false;
}

}
}

public boolean isSelectedHeader(int pos) {
Object identifier = null;
if(this.getDataSet().getColumn(pos).isHidden() == true) {
return false;
}
else {
identifier = this.getDataSet().getColumn(pos).getColumnName();
CSCheckBoxHeader chk = (CSCheckBoxHeader) getColumn(identifier).
getHeaderRenderer();
return chk.isSelected();
}
}

/*
overriding JdbTable mouseClicked
um den Renderer unabhängig von der Sortierung zu verwenden, muss die
Position
berechnet werden.
Bei einem click auf die Checkbox wird aktiviert/deaktiviert
Bei click auf den Spaltentitel, wird die Spalte sortiert
*/

public void mouseClicked(MouseEvent e) {
int tableColumn = getTableHeader().columnAtPoint(e.getPoint());
boolean sort = true;
int pos = this.getTableHeader().getColumnModel().getColumn(tableColumn).
getWidth();
Rectangle rec = this.getTableHeader().getHeaderRect(tableColumn);

if (e.getSource() == getTableHeader() &&
tableColumn != -1 && e.getX() <= rec.getX() + 20) {
sort = false;
JTableHeader hd = this.getTableHeader();
TableCellRenderer rend = hd.getColumnModel().getColumn(tableColumn).
getHeaderRenderer();

if (rend instanceof CSCheckBoxHeader) {
if ( ( (CSCheckBoxHeader) rend).isSelected()) {
( (CSCheckBoxHeader) rend).setSelected(false);
}
else {
( (CSCheckBoxHeader) rend).setSelected(true);
}
}
}

else {
super.mouseClicked(e);
}
}
}

"Olaf Raether" <olaf (AT) epro (DOT) de> schrieb im Newsbeitrag
news:4448d5ef$1 (AT) newsgroups (DOT) borland.com...
Quote:
From my point of view you have to override the method

public void createDefaultColumnsFromModel()

from JDbTable. In this method everything happens.I hope you have
enterprise version, and you are able to take a look at the source of
JdbTable. There you find the "setHeaderRenderer" method.

Then you have a write a method that looks similar like this.

public void createDefaultColumnsFromModel() {
super.createDefaultColumnsFromModel();
Object identifier=null;
for (int i=0;i<this.getDataSet().getColumnCount();i++) {
identifier = this.getDataSet().getColumn(i).getColumnName();
getColumn(identifier).setHeaderRenderer(new YourRenderer());
}
}

This code is not complete. But i think this one possible solution and give
you a hint.

Hope this helps.


Olaf Raether



Christa Schneider wrote:
Hi,
thanks for the answer, but this is not my problem.
I will write a new HeaderRenderer with a JCheckbox. The example with the
new Renderer works with JTable but not with JdbTable and I don't know
why.
Maybe anyone have had the same problem...
Thanks
Christa



"Kevin Dean [TeamB]" <NkOdSePaAnM (AT) datadevelopment (DOT) com> schrieb im
Newsbeitrag news:xn0el7k53kzzy002-kdean (AT) www (DOT) teamb.com...
Christa Schneider wrote:

Hi,

I'am trying to change the Header of a JdbTable. If I do the same with
a JTable it works fine.
Can anybody help me?

Here is the example:
...
TableCellRenderer rd = new CSCheckBoxHeader();
table.getColumnModel().getColumn(1).setHeaderRenderer(rd);
...

public class CSCheckBoxHeader extends JCheckBox implements
TableCellRenderer {

public CSCheckBoxHeader() {
super();
}

public Component getTableCellRendererComponent(JTable table, Object
value,
boolean isSelected,
boolean hasfocus,
int row, int col) {
...
//header.addMouseListener(this);
return this;
}

The JdbTable gets the column header names from the Column objects in the
data set. Use the Column.setCaption() method.

--
Kevin Dean [TeamB]
Dolphin Data Development Ltd.
http://www.datadevelopment.com/

NEW WHITEPAPERS
Team Development with JBuilder and Borland Enterprise Server
Securing Borland Enterprise Server
http://www.datadevelopment.com/papers/index.html

Please see Borland's newsgroup guidelines at
http://info.borland.com/newsgroups/guide.html




Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> JBuilder DB Swing All times are GMT
Page 1 of 1

 
Jump to:  
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


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.