🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: overwrite JTable cell.

#7877
From: John McGrath TeamB
Date: Tue, 05 Dec 2000 00:00
44 lines
2358 bytes
On Mon, 4 Dec 2000 16:20:32 -0500, Zachary Cooper wrote:

Note: The way you posted your last message makes it look like I wrote 
it.  If you use the "Reply to Group" button in Outlook Express, it will 
add ">" quoting marks when it inserts the original message text.  It 
will also place a reference to the original message in the header so 
that most news readers will list the message as a reply.

> I've added a FocusListener, ActionListener, and KeyListener to
> a custom TableCellEditor and to my custom JTable, but I am only
> able to do a selectAll() when I mouse-click in a cell.  When I
> mouse-click, the TableCellEditor gets a FocusEvent and I then
> do a selectAll() which results in a overwrite when I begin to type.
> I want the same thing to happen when I enter a new cell using a
> key-press, but the new cell entered doesn't become highlighted
> when I do a selectAll when entered...

If you move the JTable's cursor to the cell using the arrow or tab 
keys, it does not actually begin editing the cell, so the table cell 
editor component has not yet been created or realized.  So the 
listeners that you add to the component will not have any effect.

If you then press a typing key, the cell editor will then be created, 
but the timing is a little different then in the case you cited, due to 
the way that the mouse click and keyboard events are re-targeted and 
how the focus is transferred to the TTableCellEditor.

You can deal with this by having your component defer the selectAll() 
call using SwingUtilities.invokeLater().  For example:

    SwingUtilities.invokeLater( new Runnable() {
        public void run() {
            selectAll();
        }
    } );

-- 
Regards,

John McGrath [TeamB]

---------------------------------------------------
Before sending me e-mail, please read:
    http://www.JPMcGrath.net/newsgroups/e-mail.html
Technical Details
Message-ID: <MPG.14968ac52c98d6a5989d96@forums.borland.com>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <3a2c09c3$1_2@dnews>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 111d45,c575b74c2bce15b4
X-Google-Attributes: gid111d45,public
From: John McGrath  [TeamB] <ng-b@JPMcGrath.net>
Subject: Re: overwrite JTable cell.
Date: 2000/12/05
Message-ID: <MPG.14968ac52c98d6a5989d96@forums.borland.com>
X-Deja-AN: 701306332
References: <3a2c09c3$1_2@dnews>
Organization: Another Netscape Collabra Server User
Newsgroups: borland.public.jbuilder.java.swing