Thread View: borland.public.jbuilder.java.swing
6 messages
6 total messages
Started by Sam Seaborn
Tue, 04 May 2004 21:27
how to do a JList filled with JCheckboxes?
Author: Sam Seaborn
Date: Tue, 04 May 2004 21:27
Date: Tue, 04 May 2004 21:27
14 lines
1290 bytes
1290 bytes
Hi, I'm trying to do a JList of JCheckboxes (like in JBX's 'close projects' dialog box). I have implemented a JTable with two columns, one for the checkbox and one for the label. But it's not exactly what I want, and not as nice as JBX's. Also, I tried dynamically GridBagLayout-ing JCheckBoxes on a JPanel to duplicate the behaviour, but that turned out even worse. How would you Swing gurus do it? Sam
Re: how to do a JList filled with JCheckboxes?
Author: George
Date: Tue, 04 May 2004 21:55
Date: Tue, 04 May 2004 21:55
29 lines
1763 bytes
1763 bytes
You can implement your own javax.swing.ListCellRenderer for the JList and implement the getListCellRendererComponent method to return a check box. The check box comes with its own label (see setText() method); so you don't need to handle that separately. ListCellRender is an interface. DefaultListCellRenderer is a concrete class that extends JLabel. HTH. "Sam Seaborn" <sam@rightclick.ca> wrote in message news:40980aed$1@newsgroups.borland.com... > Hi, > > I'm trying to do a JList of JCheckboxes (like in JBX's 'close projects' > dialog box). > > I have implemented a JTable with two columns, one for the checkbox and one > for the label. But it's not exactly what I want, and not as nice as JBX's. > > Also, I tried dynamically GridBagLayout-ing JCheckBoxes on a JPanel to > duplicate the behaviour, but that turned out even worse. > > How would you Swing gurus do it? > > Sam > >
Re: how to do a JList filled with JCheckboxes?
Author: George
Date: Wed, 05 May 2004 13:38
Date: Wed, 05 May 2004 13:38
41 lines
2173 bytes
2173 bytes
After a good night's sleep I realize your question was addressed to swing gurus. You will surely excuse my impetuousness. :-) "George" <geo_54321@yahoo.com> wrote in message news:409810e5$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. The > check box comes with its own label (see setText() method); so you don't need > to handle that separately. > > ListCellRender is an interface. DefaultListCellRenderer is a concrete class > that extends JLabel. > > HTH. > > "Sam Seaborn" <sam@rightclick.ca> wrote in message > news:40980aed$1@newsgroups.borland.com... > > Hi, > > > > I'm trying to do a JList of JCheckboxes (like in JBX's 'close projects' > > dialog box). > > > > I have implemented a JTable with two columns, one for the checkbox and one > > for the label. But it's not exactly what I want, and not as nice as > JBX's. > > > > Also, I tried dynamically GridBagLayout-ing JCheckBoxes on a JPanel to > > duplicate the behaviour, but that turned out even worse. > > > > How would you Swing gurus do it? > > > > Sam > > > > > >
Re: how to do a JList filled with JCheckboxes?
Author: Sam Seaborn
Date: Wed, 05 May 2004 18:00
Date: Wed, 05 May 2004 18:00
13 lines
1514 bytes
1514 bytes
> > 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
Re: how to do a JList filled with JCheckboxes?
Author: Sam Seaborn
Date: Wed, 05 May 2004 18:20
Date: Wed, 05 May 2004 18:20
28 lines
1557 bytes
1557 bytes
FYI, I found an interesting solution here: http://www.devx.com/tips/Tip/5342 Thanks, Sam "Sam Seaborn" <sam@rightclick.ca> wrote in message news:40980aed$1@newsgroups.borland.com... > Hi, > > I'm trying to do a JList of JCheckboxes (like in JBX's 'close projects' > dialog box). > > I have implemented a JTable with two columns, one for the checkbox and one > for the label. But it's not exactly what I want, and not as nice as JBX's. > > Also, I tried dynamically GridBagLayout-ing JCheckBoxes on a JPanel to > duplicate the behaviour, but that turned out even worse. > > How would you Swing gurus do it? > > Sam > >
Re: how to do a JList filled with JCheckboxes?
Author: 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 > >
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads