Article View: borland.public.jbuilder.java.swing
Article #13336Re: How can I know the row number of selected item.
From: Tapio Holopainen
Date: Thu, 13 Aug 1998 00:00
Date: Thu, 13 Aug 1998 00:00
36 lines
1626 bytes
1626 bytes
ParkNoJun wrote:
>
> Hi all.
>
> I want to know the row number of selected item in JTable.
> I tried many ways but I failed. Help me!.
> Give me the idea or simple source code if possible.
>
> Thanks in advance.
This is the one way to do it (maybe not the best...)
first implement ListSelectionListener interface
put these 3 lines e.g on JApplet's init():
ListSelectionModel listSelection = table.getSelectionModel();
listSelection.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
listSelection.addListSelectionListener(this);
and write valueChanged -method:
public void valueChanged(ListSelectionEvent e)
{
ListSelectionModel listSelection = (ListSelectionModel)e.getSource();
if(!listSelection.isSelectionEmpty())
{
int min = listSelection.getMinSelectionIndex();
int max = listSelection.getMaxSelectionIndex();
for(int i=min;i<=max;i++)
if(listSelection.isSelectedIndex(i))
System.out.println("ROW "+i+" IS SELECTED");
}
}
Technical Details
Message-ID:
<35D2DBFA.77B2706F@sysline.com>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<35BF763D.C9909CF8@mail.saint.co.kr>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 111d45,f99918f732fa5e38,start X-Google-Attributes: gid111d45,public From: Tapio Holopainen <tapio.holopainen@sysline.com> Subject: Re: How can I know the row number of selected item. Date: 1998/08/13 Message-ID: <35D2DBFA.77B2706F@sysline.com> X-Deja-AN: 380725669 Content-Transfer-Encoding: 7bit References: <35BF763D.C9909CF8@mail.saint.co.kr> To: ParkNoJun <njpark@mail.saint.co.kr> X-Accept-Language: en Content-Type: text/plain; charset=us-ascii Organization: Sysline Oy Mime-Version: 1.0 Newsgroups: borland.public.jbuilder.java.swing