Board index » jbuilder » JTableHeader why not editable?

JTableHeader why not editable?


2004-05-26 04:09:34 AM
jbuilder14
Why is the JTableHeader not editable. I want to create an editable
JTableHeader but I cannot understand why if I use the
setHeaderRenderer method the header is not editable.
I have seen (www.esus.com/javaindex/j2se/jdk1.2/javaxswing/editableatomiccontrols/jtable/jtableeditableheader.html)
an example of editable JTableHeader. But why isn't enough the follow
code
....
TableColumnModel colModel = jTable1.getColumnModel();
for (int col = 0; col < jTable1.getColumnCount(); col++)
{
colModel.getColumn(col).setHeaderRenderer(new HeaderFilterRenderer());
}
.....
class HeaderFilterRenderer implements TableCellRenderer
{
public Component getTableCellRendererComponent(JTable table, Object
value,
boolean isSelected, boolean hasFocus, int rowIndex, int vColIndex)
{
return new JTextField ();
}
}
 
 

Re:JTableHeader why not editable?

hi,
the fact that you are returning the jtextfield as the renderer will not make
the header editable: the framework will just use your control's paint method
to actually render the current header cell and that's it.
for example to have the cell editable, the framework actually gets the edit
field, put it in the appropriate place, make it visible and set the focus to
it. This is the editor, different from the renderer.
This complicated thing is not implemented for the header. If you really want
this you will have to implement it yourself and it will take you some time,
it's quite a challenging stuff...
Daniel
"ftirapelle" < XXXX@XXXXX.COM >wrote in message
Quote
Why is the JTableHeader not editable. I want to create an editable
JTableHeader but I cannot understand why if I use the
setHeaderRenderer method the header is not editable.
I have seen
(www.esus.com/javaindex/j2se/jdk1.2/javaxswing/editableatomiccontrols
/jtable/jtableeditableheader.html)
Quote
an example of editable JTableHeader. But why isn't enough the follow
code

....
TableColumnModel colModel = jTable1.getColumnModel();
for (int col = 0; col < jTable1.getColumnCount(); col++)
{
colModel.getColumn(col).setHeaderRenderer(new HeaderFilterRenderer());
}
.....
class HeaderFilterRenderer implements TableCellRenderer
{

public Component getTableCellRendererComponent(JTable table, Object
value,
boolean isSelected, boolean hasFocus, int rowIndex, int vColIndex)
{
return new JTextField ();
}

}