Click here to Skip to main content
15,891,431 members
Home / Discussions / Java
   

Java

 
QuestionRe: image procesing in java Pin
bharath S h14-Dec-11 15:27
bharath S h14-Dec-11 15:27 
GeneralRe: image procesing in java Pin
RaviRanjanKr3-Dec-11 10:17
professionalRaviRanjanKr3-Dec-11 10:17 
GeneralRe: image procesing in java Pin
bharath S h1-Mar-12 17:37
bharath S h1-Mar-12 17:37 
Questionarray sort performance java vs .net c# Pin
nipsonanomimata29-Nov-11 3:12
nipsonanomimata29-Nov-11 3:12 
AnswerRe: array sort performance java vs .net c# Pin
David Skelly29-Nov-11 3:46
David Skelly29-Nov-11 3:46 
AnswerRe: array sort performance java vs .net c# Pin
TorstenH.30-Nov-11 0:49
TorstenH.30-Nov-11 0:49 
GeneralRe: array sort performance java vs .net c# Pin
nipsonanomimata30-Nov-11 1:03
nipsonanomimata30-Nov-11 1:03 
QuestionJTable cell not going away! SOLVED Pin
venomation26-Nov-11 16:34
venomation26-Nov-11 16:34 
SOLUTION:
This works for me but I still do not know why it was behaving like that...

Java
if (table.getCellEditor() != null) {
            table.getCellEditor().stopCellEditing();
        }


Was called when deleting the row, forcing the cell that is being edited to stop editing.

PROBLEM:

I have the following CellEditor that is used to validate cells on a column:

Java
public class CellEditor extends AbstractCellEditor implements TableCellEditor {

    protected TextField source = new TextField();
    private ArrayList<IValidator> validators = new ArrayList<IValidator>();

    public CellEditor WithValidation(IValidator validator) {
        validators.add(validator);
        return this;
    }

    public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) {
 
        source.setText(String.valueOf(value));
        return source;
    }

    public Object getCellEditorValue() {
        return source.getText();
    }

    @Override
    public boolean stopCellEditing() {
        String s = ((String) this.getCellEditorValue());
        if (s == null) {
            this.fireEditingCanceled();
            return false;
        }

        for (IValidator v : this.validators) {
            if (!v.isValid(s)) {
                JOptionPane.showMessageDialog(null, v.getErrorMessage());
                this.fireEditingCanceled();
                return false;
            }
        }
        return super.stopCellEditing();
    }
}


And I attach the code to my table like this:
Java
this.jTable1.getColumnModel()
                .getColumn(0)
                .setCellEditor(new loyaltyapp.validation.CellEditor()
                .WithValidation(new TextLengthValidator(1, 12)));


When the second snippet of code is commented everything works as intended (but of course not including any validation)...

The problem is that when I do attach the CellEditor to my table when I remove a row WHILE a cell is being edited the rest of the row gets deleted, leaving behind a rogue cell!

Image of selecting a cell:
http://www.mediafire.com/?8n999a4djacdj84[^]

Image of deleting the row while selecting the validation cell:
http://www.mediafire.com/?mozjjzc53ju12b2[^]


The only way to remove it is by pressing escape...

Any ideas? Confused | :confused:
AnswerRe: JTable cell not going away! SOLVED Pin
TorstenH.27-Nov-11 22:33
TorstenH.27-Nov-11 22:33 
Questionhelp.... Pin
djamelm6126-Nov-11 1:50
djamelm6126-Nov-11 1:50 
AnswerRe: help.... Pin
Richard MacCutchan26-Nov-11 2:39
mveRichard MacCutchan26-Nov-11 2:39 
GeneralRe: help.... Pin
mirzabeigi8-Dec-11 7:42
mirzabeigi8-Dec-11 7:42 
AnswerRe: help.... Pin
RaviRanjanKr26-Nov-11 3:40
professionalRaviRanjanKr26-Nov-11 3:40 
AnswerRe: help.... Pin
SilimSayo28-Nov-11 6:06
SilimSayo28-Nov-11 6:06 
SuggestionRe: help.... Pin
RaviRanjanKr3-Dec-11 10:21
professionalRaviRanjanKr3-Dec-11 10:21 
AnswerRe: help.... Pin
Aniket S Kulkarni28-Nov-11 20:11
Aniket S Kulkarni28-Nov-11 20:11 
GeneralRe: help.... Pin
RaviRanjanKr3-Dec-11 10:28
professionalRaviRanjanKr3-Dec-11 10:28 
GeneralRe: help.... Pin
SilimSayo19-Dec-11 15:44
SilimSayo19-Dec-11 15:44 
AnswerRe: help.... Pin
TorstenH.29-Nov-11 0:00
TorstenH.29-Nov-11 0:00 
GeneralRe: help.... Pin
Richard MacCutchan29-Nov-11 0:47
mveRichard MacCutchan29-Nov-11 0:47 
GeneralRe: help.... Pin
TorstenH.29-Nov-11 19:38
TorstenH.29-Nov-11 19:38 
Questionhow to create constructor for array? Pin
rohaya8815-Nov-11 0:53
rohaya8815-Nov-11 0:53 
AnswerRe: how to create constructor for array? Pin
TorstenH.15-Nov-11 1:16
TorstenH.15-Nov-11 1:16 
GeneralRe: how to create constructor for array? Pin
rohaya8815-Nov-11 1:46
rohaya8815-Nov-11 1:46 
GeneralRe: how to create constructor for array? Pin
TorstenH.15-Nov-11 2:01
TorstenH.15-Nov-11 2:01 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.