The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

This topic is READ ONLY
import-bot (20211) [Avatar] Offline
#1
[Originally posted by ian]


Hi Folk!

So, I have this table and row 0 is editable with a JComboBox which has been
addeded with a

myTable.getColumn("UserID").setCellEditor(new DefaultCellEditor(myComboBox));

The snag is that I want to adjust the items of the combo box AFTER the mouse
has been clicked in the cell to invoke editing but BEFORE the combo is
displayed. I need to add and remove items from the combo depending on where
the user has clicked in the table.

Many thanks to all those involved.

Cheers
import-bot (20211) [Avatar] Offline
#2
Re: JTable Cells and JCombo Box's
[Originally posted by matt]

By adding a MouseListener to your JTable, in the mousePressed() method you can
determine the clicked cell like this:

Point p = e.getPoint();
int row = myJTable.rowAtPoint(p);
int column = myJTable.columnAtPoint(p);
if (row == -1 || column == -1) {
return;
}
else {
// do what you want with your JComboBox
// here if the cell matches row and column.
}

See chapter 18 of our "Swing" book (available from Manning)
or online at http://www.spindoczine.com/sbe
import-bot (20211) [Avatar] Offline
#3
Not working! (Was: Re: JTable Cells and JCombo Box's
[Originally posted by ian]


Thanks Matt, this does indeed determine if the table cell is being edited, but
the problem I failed to articulate is that the JComboBox has (or appears to
be) partially initialized in some manner. So, when I delete, add and perform
actions on the *members* in the JComboBox, I get unpredictable results. These
include height miss-calculations (random height even if I explicitly set the
height), missing members and I hate to say it, just plain wierdness.

Is there a way to overload the startEditing or the method(s) called to
initialize the JCombo editor? I have tried numerous techniques to beat the
Combo into behaving correctly and the only one that I think would work would
be to get to the Combo *before* the JTable has started editing.

Thanks once again!

> By adding a MouseListener to your JTable, in the mousePressed() method you can
> determine the clicked cell like this:
>
> Point p = e.getPoint();
> int row = myJTable.rowAtPoint(p);
> int column = myJTable.columnAtPoint(p);
> if (row == -1 || column == -1) {
> return;
> }
> else {
> // do what you want with your JComboBox
> // here if the cell matches row and column.
> }
>
> See chapter 18 of our "Swing" book (available from Manning)
> or online at http://www.spindoczine.com/sbe