🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.jbuilder.java.swing
Article #9590

Re: A customized TableCellEditor in a JTable does not work!

#9590
From: Martin Dahlem
Date: Thu, 02 Mar 2000 00:00
53 lines
2588 bytes
Now I can be more specific:
The correct TableCellEditor is used
and the correct TableCellEditor's
Component is used, the only thing what is wrong:

I do not get any key-event until I click into the tablecell!!!

I added a DocumentListener to my TableCellEditor's
Component: this works fine!!

If you know a way to make the TableCellEditor's
Component's KeyListener to receive the keyevents without
using the mouse before, I will be happy to get
your answer!

Thanx, Martin

Martin Dahlem wrote:

> Dear all,
> I want to validate user-inputs in
> a JTable. When I set a new TableCellEditor
> to any column, it is used only when I doubleclick
> in the cell. Then it works fine so far.
> Otherwise (setting the focus to the cell
> by using the TAB-key or by clicking only once in it)
> my cellEditor is not used for this cell and
> the user can type all the invalid characters
> my cellEditor should filter out.
> If I use
> "cellEditor.setClickCountToStart(0);",
> I make my cellEditor work after a single click
> in the cell. But how can I make it work after
> setting the focus to a cell by using the TAB-key????
>
> Thank you for any tip or hint!
>
> Here is my example:
>
>   Vector data = new Vector();
>   Vector columNames = new Vector();
>   columNames.addElement("Connection");
>   columNames.addElement("AsId");
>   JTable tableAsIds = new JTable();
>   tableAsIds.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
>   tableAsIds.setModel(new DefaultTableModel(data, columNames));
>   JScrollPane tableScroller = new JScrollPane(tableAsIds);
>   add(tableScroller);
>   JTextField tf = new JTextField();
>   tf.addKeyListener(new NumberValidator());
>   DefaultCellEditor cellEditor = new DefaultCellEditor(tf);
>   cellEditor.setClickCountToStart(0);
>   tableAsIds.getColumnModel().getColumn(1).setCellEditor(cellEditor);
Technical Details
Message-ID: <38BE95FC.A8844966@germany.ncr.com>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <38BE5FF0.AA2904CD@germany.ncr.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 111d45,6edbc71d4b1ba6ae
X-Google-Attributes: gid111d45,public
From: Martin Dahlem <martin.dahlem@germany.ncr.com>
Subject: Re: A customized TableCellEditor in a JTable does not work!
Date: 2000/03/02
Message-ID: <38BE95FC.A8844966@germany.ncr.com>
X-Deja-AN: 592277380
Content-Transfer-Encoding: 7bit
References: <38BE5FF0.AA2904CD@germany.ncr.com>
X-Original-NNTP-Posting-Host: ncrnews.daytonoh.ncr.com
X-Accept-Language: en
Content-Type: text/plain; charset=us-ascii
X-Trace: 2 Mar 2000 08:18:29 -0800, 192.127.94.7
MIME-Version: 1.0
Reply-To: martin.dahlem@germany.ncr.com
Newsgroups: borland.public.jbuilder.java.swing