Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Andrzejek on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

shouldSelectCell() in DefaultCellEditor not working?

Status
Not open for further replies.

lesneskp

Programmer
Jul 3, 2002
19
US
Hi all,

I have created a simple class that extends DefaultCellEditor (see below), but it appears that shouldSelectCell() is not working - the cell's contents do not get selected.

Advice much appreciated!!



class PaymentCellEditor extends javax.swing.DefaultCellEditor {

public PaymentCellEditor(javax.swing.JTextField textField){

super(textField);
clickCountToStart = 1;

}

public boolean shouldSelectCell(java.util.EventObject anEvent) {

return true;

}

}
 
shouldSelectCell(Event) is there for if you wished to allow someone to edit another cell whilst holding selection of the current cell.

In DefaultCellEditor it will be true already as standard behaviour is that if you are editing something it is assumed that you are currently selecting it too. Jeremy Nicholson, Director of a UK-based Java and Data Warehousing consultancy
 
Hmmm, thanks - I misunderstood the meaning of that method. That must be why it didn't seem to have the effect I wanted (when the user clicks into the cell, its contents all get selected/highlighted). I accomplished that in the end by overriding/catching the focus event on the text field I have in the cell.

I don't quite understand what you mean by keeping a cell selection while another cell is being edited... how would this be accomplished?
 
If you are on a cell then go to another and edit it, you have effectively selected that cell then edited it. I believe that shouldSelect(false) would enable an edit to be started on another cell without it being flagged as currently selected. In the javadoc they give an example of "A table that contains a column of check boxes, the user might want to be able to change those checkboxes without altering the selection".

Not sure if this enlightens you, might just be one of those things that you've got to try out and see what happens. Jeremy Nicholson, Director of a UK-based Java and Data Warehousing consultancy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top