Article View: borland.public.jbuilder.java.swing
Article #687Re: JTable & Popup Menu
From: Erica Wheatcroft
Date: Tue, 18 Jan 2005 22:35
Date: Tue, 18 Jan 2005 22:35
63 lines
2575 bytes
2575 bytes
So i changed the function to do the following and it works: but is this they
"correct" way to implement this behavior?
private void editTable_MouseReleased(MouseEvent e)
{
// we only want a to do this if the event is a pop up trigger.
if(e.isPopupTrigger())
{
Point p = e.getPoint();
int row = _structureMembersTable.rowAtPoint(p);
int col = _structureMembersTable.columnAtPoint(p);
if(table.isRowSelected( row ) == false)
{
table.setRowSelectionInterval(row,row);
}
table.setEditingRow( row );
popupMenu.show( e.getComponent(), e.getX(), e.getY());
}
}
"Erica Wheatcroft" <erica.wheatcroft@gmail.com> wrote in message
news:41ed7406$1@newsgroups.borland.com...
> Hi -
>
> I have a JTable that I have created and what to have a popup menu
> appear when the user right clicks on a row in the table
>
> so i wrote the following code:
>
> in jninit()
>
> table.addMouseListener(new MouseAdapter()
> {
> public void mouseReleased(MouseEvent e)
> {
> editTable(e);
> }
> });
>
> ...
>
> private void editTable_MouseReleased(MouseEvent e)
> {
> if(e.isPopupTrigger())
> {
>
> _enumMembersTable.setEditingRow(_enumMembersTable.rowAtPoint(e.getPoint()));
> _membersPopupMenu.show(e.getComponent(), e.getX(), e.getY());
> }
> }
>
> However when i run the app and try to right click on a row the row is
> never selected. I have simular code for a jlist and it works great. What
> am i missing?
>
> Thanks in advance.
>
> Erica
>
Technical Details
Message-ID:
<41ed8f4b$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!proxad.net!gatel-ffm!gatel-ffm!194.25.134.126.MISMATCH!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailReferences:
<41ed7406$1@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: 111d45,3d8097fef9530864 X-Google-Attributes: gid111d45,public X-Google-Language: ENGLISH,ASCII-7-bit Reply-To: "Erica Wheatcroft" <erica.wheatcroft@gmail.com> From: "Erica Wheatcroft" <erica.wheatcroft@gmail.com> Newsgroups: borland.public.jbuilder.java.swing References: <41ed7406$1@newsgroups.borland.com> Subject: Re: JTable & Popup Menu Date: Tue, 18 Jan 2005 16:35:55 -0600 Lines: 65 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.2180 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180 X-RFC2646: Format=Flowed; Response NNTP-Posting-Host: 206.127.10.170 Message-ID: <41ed8f4b$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1106087755 206.127.10.170 (18 Jan 2005 14:35:55 -0800) Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!proxad.net!gatel-ffm!gatel-ffm!194.25.134.126.MISMATCH!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail