Hi,
I wrote a JTable with a custom table header that shows a label; if you
click the header, a combobox appears and you can choose a value (used
for filtering values): After selecting an object in the combobox, the
original label should be shown, but the label shows the chosen value
from the combobox. If I set the value of the table header the same
time I get the value from the combobox and do a repaint, the chosen
value is still shown. The value of the header is right, but it is not
shown.
But if I set the value "manually" (another combo box or a button), it
works.
Here a piece of code:
if (e.getActionCommand().equals("comboBoxChanged")) {
CustomComboBox box = (CustomComboBox) e.getSource();
if (box.getSelectedIndex() == -1) {
box.setSelectedIndex(box.getSel());
return;
}
if (box.getSel() != box.getSelectedIndex()) {
box.setSel(box.getSelectedIndex());
System.out.println("Selected: " +
box.getSelectedItem() + ": " + box.getColumn());
}
table.getColumnModel().getColumn(box.getColumn()).setHeaderValue(box.getDisplayName());
System.out.println(table.getColumnModel().getColumn(box.getColumn()).getHeaderValue());
table.getTableHeader().repaint();
}
Thank you,
Sascha
Nick Pomfret - 30 Aug 2004 11:39 GMT
I know this isn't quite answering your question, but have you thought about
changing your app so that instead of changing your table header into a combo
box, you put an extra row into the top of your table with the combo boxes in
(like Excel does when you apply filters)?
Otherwise, the way I've accomplished something similar in the past is to
create a panel with a combo box in and show it on top of the table header.
That way you don't need to mess around with changing your table header.
I've actually found both of these solutions slightly cumbersome from a users
point of view. If your combo boxes have a large number of values listed in
them it can be difficult to find the value you're after. Also, you have to
scroll to the top of the table in order to apply your filter. My preferred
solution is to allow the user to click on a value in the JTable and allow
them to filter by that value (from some sort of pop-up menu). My current
project uses this approach (www.tabletoolkit.com).

Signature
** http://www.tabletoolkit.com **
Aggregate a JTable to an arbitrary level to create your own pivot tables
> Hi,
>
[quoted text clipped - 24 lines]
> box.getSelectedItem() + ": " + box.getColumn());
> }
table.getColumnModel().getColumn(box.getColumn()).setHeaderValue(box.getDisp
layName());
System.out.println(table.getColumnModel().getColumn(box.getColumn()).getHead
erValue());
> table.getTableHeader().repaint();
> }
>
> Thank you,
>
> Sascha
Sascha Moellering - 31 Aug 2004 12:33 GMT
Thank you very much,
this is a great idea and - maybe - solves another problem that occured
a few hours ago.
Thank you (once again),
Sascha
> I know this isn't quite answering your question, but have you thought about
> changing your app so that instead of changing your table header into a combo
[quoted text clipped - 12 lines]
> them to filter by that value (from some sort of pop-up menu). My current
> project uses this approach (www.tabletoolkit.com).
Jacob - 31 Aug 2004 12:58 GMT
> I wrote a JTable with a custom table header that shows a label; if you
> click the header, a combobox appears and you can choose a value (used
> for filtering values)
The header use the cell component renderer to create
an _image_ of the component; The component as such
is not really there; not accessible anyway.
Why they did it like this, I don't know.