I agree but only thing is that now any dialog which uses these
editors, will have to implement this interface to make sure that
values are either accepted or rejected. I created editors to be
self sufficient so that no other manager has to do anything. I can
put this work around until java bug is fixed ( The java bug is that
when user starts editing, the focus does not get trasferred to the
editing cell properly ) 

- Peter

--- Sachin Hejip <[EMAIL PROTECTED]> wrote:
> I see what you mean - the problem is that I should have been clearer
> in my
> reply :-).
> 
> I meant that you should add that code snippet in the OK Button's
> ActionListener. Later, I did notice your post to Anand about the
> dialog not
> knowing whether the panel has a table or not. I would suggest that
> you
> create a panel that conforms to some interface say Editable. In the
> interface has an acceptEditedValues() method and let the panel decide
> what
> to call - that snippet if it has a table or nothing if not needed.
> The
> dialog will now work only with Editable panels and in the Ok Button's
> actionListener you can call editablePanel.acceptEditedValues().
> 
> Ofcourse, this is not a Swing specific solution but in the light of
> all the
> issues you are facing do you think this might be the cleaner
> solution?
> 
> Regards
> Sachin
> 
> ----- Original Message -----
> From: "Peter Peterson" <[EMAIL PROTECTED]>
> To: "Sachin Hejip" <[EMAIL PROTECTED]>; "Anand Hariharan"
> <[EMAIL PROTECTED]>; <[EMAIL PROTECTED]>
> Sent: Tuesday, December 24, 2002 12:05 AM
> Subject: Re: JTable editing problem...
> 
> 
> > Sachin,
> > I think you missed my point. If user clicks on OK, then the dialog
> will
> > go away and stopCellEditing will never get called. This problem
> > is because of a bug in focus management as pointed by someone in
> > this forum
> >
> > rgds,
> > Peter
> >
> > --- Sachin Hejip <[EMAIL PROTECTED]> wrote:
> > > Yep, it saves it.
> > > stopCellEditing() accepts the value entered by the user.
> > >
> > > Regards
> > > Sachin
> > > ----- Original Message -----
> > > From: "Peter Peterson" <[EMAIL PROTECTED]>
> > > To: "Sachin Hejip" <[EMAIL PROTECTED]>; "Anand Hariharan"
> > > <[EMAIL PROTECTED]>; <[EMAIL PROTECTED]>
> > > Sent: Saturday, December 21, 2002 2:59 AM
> > > Subject: Re: JTable editing problem...
> > >
> > >
> > > > Sachin,
> > > >
> > > > I did this. The problem I have here is what if user has entered
> > > > a correct value in the cell and then clicked  on OK button ?
> > > > In this case he is expecting that the value would be saved
> > > >
> > > > - Peter
> > > >
> > > > --- Sachin Hejip <[EMAIL PROTECTED]> wrote:
> > > > > The following snippet should solve the problem -
> > > > >
> > > > >                         int editingColumn =
> > > table.getEditingColumn();
> > > > >                         TableCellEditor defaultEditor =
> > > > >
> > > >
> > >
> >
>
table.getDefaultEditor(table.getModel().getColumnClass(editingColumn));
> > > > >                         defaultEditor.stopCellEditing();
> > > > >
> > > > >
> > > > > If you have set editors on the table column then use the
> > > columnModel
> > > > > to get
> > > > > the TableColumn.
> > > > >
> > > > > Hope this helps.
> > > > >
> > > > > Regards
> > > > > Sachin
> > > > >
> > > > >
> > > > > ----- Original Message -----
> > > > > From: "Peter Peterson" <[EMAIL PROTECTED]>
> > > > > To: "Anand Hariharan" <[EMAIL PROTECTED]>;
> <[EMAIL PROTECTED]>
> > > > > Sent: Friday, December 20, 2002 7:14 AM
> > > > > Subject: Re: JTable editing problem...
> > > > >
> > > > >
> > > > > > Anand,
> > > > > >
> > > > > > I should have given more information. The dialog has a
> panel
> > > which
> > > > > > has different data editors depending on how it is invoked.
> In
> > > some
> > > > > > cases, the panel may not even have a table. In short,
> dialog
> > > > > doesnot
> > > > > > have an idea of what is being edited. In some cases, its
> > > JTable,
> > > > > > in some cases its just a JTextField or it could anything
> else.
> > > > > >
> > > > > > If I make OK button to find out what it is, I am making
> dialog
> > > > > > sensitive to data editor instance which I wanted to avoid
> > > because
> > > > > > its a not a good bean design pattern.
> > > > > >
> > > > > > let me know if there is any other way out.
> > > > > >
> > > > > > Also I have noticed that if I set a cell editor on a table,
> > > then
> > > > > > I can start editing cell, either by single clicking or
> double
> > > > > clicking.
> > > > > > BUUUT...surprisngly enough ONLY when I double click, I see
> my
> > > > > > JTextField
> > > > > > table cell renderer otherwise for single click JTable
> renders
> > > > > something
> > > > > > else than what I set !!!!!!!!!!!! ( My cell renderer which
> is a
> > > > > > JTextField has some properties set so that it looks good
> when
> > > user
> > > > > > starts editing )
> > > > > >
> > > > > > Any idea whats going on here ?
> > > > > >
> > > > > > rgds
> > > > > > Peter
> > > > > >
> > > > > >
> > > > > > --- Anand Hariharan <[EMAIL PROTECTED]> wrote:
> > > > > > > Hi Peter :
> > > > > > >
> > > > > > > We had the same problem and this is how we handle it :
> > > > > > >
> > > > > > > Consider m_EditTable as the table that is being currently
> > > edited.
> > > > > > > Execute this code when OK is clicked.
> > > > > > >
> > > > > > >
> > > > > > > if(m_Table.isEditing())
> > > > > > > {
> > > > > > >     Component c = m_Table.getEditorComponent();
> > > > > > >     if(c != null)
> > > > > > >     {
> > > > > > >         String val = "";
> > > > > > >         if(c instanceof JTextField)
> > > > > > >             val = ((JTextField)c).getText();
> > > > > > >         /*else if( c instanceof SomeOtherComponent )
> > > > > > >             val = (String) GetStringValueFromComponent;*/
> > > > > > >         m_Table.getModel().setValueAt (val,
> > > > > m_Table.getEditingRow(),
> > > > > > > m_Table.getEditingColumn());
> > > > > > >
> > > > > > >         m_Table.removeEditor();
> > > > > > >     }
> > > > > > > }
> > > > > > >
> > > > > > > Regards,
> > > > > > > _anand
> > > > > > > [EMAIL PROTECTED]
> > > > > > >
> > > > > > > http://www.javareference.com (Articles/Examples and more
> !)
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > ----- Original Message -----
> > > > > > > From: "Peter Peterson" <[EMAIL PROTECTED]>
> > > > > > > To: <[EMAIL PROTECTED]>
> > > > > > > Sent: Thursday, December 19, 2002 9:41 AM
> > > > > > > Subject: JTable editing problem...
> > > > > > >
> > > > > > >
> > > > > > > > Hi,
> > > > > > > >
> > > > > > > > I have a JDialog which has OK/Cancel button. When user
> > > clicks
> > > > > > > > on any of these buttons, dialog goes away (
> > > setVisible(false)
> > > > > ).
> > > > > > > >
> > > > > > > > This dialog has an editable JTable. I am using a
> JTextField
> > > > > > > > as a cell editor because I wanted to capture focusLost
> 
=== message truncated ===


__________________________________________________
Do you Yahoo!?
New DSL Internet Access from SBC & Yahoo!
http://sbc.yahoo.com
_______________________________________________
Swing mailing list
[EMAIL PROTECTED]
http://eos.dk/mailman/listinfo/swing

Reply via email to