Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

jtable

0 views
Skip to first unread message

jh

unread,
May 11, 1999, 3:00:00 AM5/11/99
to
does anyone know how to do the following.
I want to validate data entered in a cell after the user
presses the enter key or the cell looses focus. If the
data is invalid then focus should return to that cell.
also anyone know of any good examples for database
data entry and update.
any ideas

thanks in advance

ej


Linda Licari

unread,
May 11, 1999, 3:00:00 AM5/11/99
to
You need to implement FocusListener and ActionListener on the cells of
interest. When the focusLost or actionPerformed methods are called do
the validation.

Hope this helps,

linda

In article <373800AE...@hotmail.com>,


--== Sent via Deja.com http://www.deja.com/ ==--
---Share what you know. Learn what you don't.---

jh

unread,
May 13, 1999, 3:00:00 AM5/13/99
to
Thankyou for the reply
When the validation fails how to i force the focus to return to the
cell.
I have tried requestFocus() but it does not seem to work. Is there any
way to
setfocus on a table Cell from inside the setValueAt() function . I have
also
tried editValueAt() but this just returns the value from the cell
without giving
the user a chance to re-edit the value.

thanks in advance

jh

Scott Lavender

unread,
May 13, 1999, 3:00:00 AM5/13/99
to
jh,

Unfortunatly, with Swing components, most of the time 'requestFocus()'
does not work as expected. The following code will do what you need. the
key here is 'invokeLater()'. This will cause your request for focus to
occur at the end of all other focus processing.


...
JTextField textField = new JTextField();
...
SwingUtilities.invokeLater( new FocusGrabber( textField ) );

/**
* Runnable inner class for refocusing JComponent.
*/
private class FocusGrabber implements Runnable
{
JComponent component;

/**
* Constructor.
*
* @parameter JComponent to refocus.
*/
public FocusGrabber( JComponent component )
{
this.component = component;
}

/**
* Run method.
*/
public void run()
{
refocusHandler( component );
}
}

/**
* Default method for refocusing an instance of JComponent
* May be overridden by child class.
*
* @param component JComponent to refocus.
*/
public void refocusHandler( JComponent component )
{
component.grabFocus();
}

In article <373AA9D3...@hotmail.com>,

--
Later.....Scott...

jh

unread,
May 16, 1999, 3:00:00 AM5/16/99
to
Thank you for the reply scott
still no joy on this. it tried the invokeLater() but it only seems to fire
once when
the table is setup. If I call editCellAt() is there any way to make the
celleditor
stay in the cell. By the way i am using java 1.2.

thanks in advance
jh

jh

unread,
May 17, 1999, 3:00:00 AM5/17/99
to
I take that back. It does work.

thankyou
jh

Patrick Forhan

unread,
May 18, 1999, 3:00:00 AM5/18/99
to
In article <373EA676...@hotmail.com>,

j wrote:
> Thank you for the reply scott
> still no joy on this. it tried the invokeLater() but it only seems to fire
> once when
> the table is setup. If I call editCellAt() is there any way to make the
> celleditor
> stay in the cell. By the way i am using java 1.2.

I think perhaps people have been giving answers (good ones, too) to the wrong
question.

If you want to validate data entry, and prevent the editor from closing in
some cases, you should look into the TableCellEditor interface, which derives
from CellEditor.

In particular, check the stopCellEditing() method in CellEditor. Its javadoc
states: " Tell the editor to stop editing and accept any partially edited
value as the value of the editor. The editor returns false if editing was not
stopped, useful for editors which validates and can not accept invalid
entries. "

Chances are, you will need to make your own full implementation of a
CellEditor/TableCellEditor, because DefaultCellEditor is really picky, and may
not suit your needs. FWIW, see the bug/RFE I submitted about it at the
bug parade, # 4222700.

Another (possibly simpler) answer is to create a custom document that does
all the validation itself... Then, just set the document of the editing
component to your custom document.

Patrick Forhan.

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own

BlueNote

unread,
May 22, 1999, 3:00:00 AM5/22/99
to
This looks good, except that I'm not using JComponents to populate my
tables, just Strings (the data is read-only). Will this approach still
work, or is there another method to grab focus?

Thanks!

jp


In article <373FEAB7...@hotmail.com>,


j wrote:
> I take that back. It does work.
>
> thankyou
> jh
>

> jh wrote:
>
> > Thank you for the reply scott
> > still no joy on this. it tried the invokeLater() but it only seems
to fire
> > once when
> > the table is setup. If I call editCellAt() is there any way to make
the
> > celleditor
> > stay in the cell. By the way i am using java 1.2.
> >

0 new messages