Article View: borland.public.jbuilder.java.swing
Article #995Re: how to do a JList filled with JCheckboxes?
From: Daniel
Date: Sun, 15 Aug 2004 05:04
Date: Sun, 15 Aug 2004 05:04
45 lines
3037 bytes
3037 bytes
hi, - you create a new renderere - rather than adding string to the list, you add objects that have at least two properties, the string you want to display and the value of the checkbox - checked or not - depending on the checked property value, you display the appropriate icon that will show the item checked or not - you can take these icons from the swing icon repository, it will surely look like a genuine Swing checkbox how you interact with it: that is the problem: - you create your own JList class - make it implement MouseListener - in mouseDown (attention, not mouseClick, that works bad in this situation) get the item under the mouse cursor, see if you are on the icon (a little math) and if so, toggle the checked value in the object in the selected item and afterwards call repaint on the object. Done so several times, works like a charm. The stuff with adding multiple controls with GridBag and getting their value: tried it either, worked for me, but it is not as elegant as the one mentioned above. Regards, Daniel "Sam Seaborn" <sam@rightclick.ca> wrote in message news:40992bef$1@newsgroups.borland.com... > > > You can implement your own javax.swing.ListCellRenderer for the JList > and > > > implement the getListCellRendererComponent method to return a check box. > > > After a good night's sleep I realize your question was addressed to swing > > gurus. You will surely excuse my impetuousness. :-) > > Anyone's opinions are useful, guru or no. ;-) > > I thought about implementing ListCellRenderer, but wouldn't I have to do a > corresponding "ListCellEditor" so I can interact with the checkboxes? > > Sam > >
Technical Details
Message-ID:
<gsqdnVwwnpVDc4PcRVn-vQ@giganews.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!news.maxwell.syr.edu!border1.nntp.dca.giganews.com!nntp.giganews.com!local1.nntp.dca.giganews.com!news.giganews.com.POSTED!not-for-mailReferences:
<40980aed$1@newsgroups.borland.com> <409810e5$1@newsgroups.borland.com> <4098edf8$1@newsgroups.borland.com> <40992bef$1@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: 111d45,e278b4d50586b83 X-Google-Attributes: gid111d45,public X-Google-Language: ENGLISH,ASCII-7-bit Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!news.maxwell.syr.edu!border1.nntp.dca.giganews.com!nntp.giganews.com!local1.nntp.dca.giganews.com!news.giganews.com.POSTED!not-for-mail NNTP-Posting-Date: Sun, 15 Aug 2004 00:04:30 -0500 From: "Daniel" <dgabrov1@yahoo.com> Newsgroups: borland.public.jbuilder.java.swing References: <40980aed$1@newsgroups.borland.com> <409810e5$1@newsgroups.borland.com> <4098edf8$1@newsgroups.borland.com> <40992bef$1@newsgroups.borland.com> Subject: Re: how to do a JList filled with JCheckboxes? Date: Sun, 15 Aug 2004 01:04:24 -0400 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1437 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1441 Message-ID: <gsqdnVwwnpVDc4PcRVn-vQ@giganews.com> Lines: 47 X-Trace: sv3-xmog9mafLC2bidXmltyKTovR1ci+3DTuVG/hkkGn+XlI4CUADXY9geLhm5XFVnHNSDNiUFGKYfoPhxN!JC4W8UjQSZHCsIuHutH3rp6Ih6xnrw2k//m5yqxUMrBG9SmEIt9nhI2Xi+XAtg== X-Complaints-To: abuse@giganews.com X-DMCA-Notifications: http://www.giganews.com/info/dmca.html X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.3.13