954,545 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

combo box containg check box as its elements in java

Hi,

I have to display a JCombobox which contains JCheckBox(containing a single character) as its elements. Combobox has to allow multiple checkbox selection.

When the selection is over, combobox has to display the selected checkbox values.

Thanks in advance,
Sagar

SSagar
Newbie Poster
13 posts since Mar 2009
Reputation Points: 10
Solved Threads: 0
 

Firstly a combo box would allow you to choose one of several choices so putting check boxes inside it which themselves are used as multiple select components would not be a good option. You could use a list box instead which itself will give you the option of selecting several options within the list so may not not have to worry about putting the check boxes in it.

verruckt24
Posting Shark
952 posts since Nov 2008
Reputation Points: 485
Solved Threads: 89
 
Firstly a combo box would allow you to choose one of several choices so putting check boxes inside it which themselves are used as multiple select components would not be a good option. You could use a list box instead which itself will give you the option of selecting several options within the list so may not not have to worry about putting the check boxes in it.


But the requirement is that way... i need to put checkbox inside combo..... and later this will be placed in a table.
Plz give me some suggestion for this.

SSagar
Newbie Poster
13 posts since Mar 2009
Reputation Points: 10
Solved Threads: 0
 

The addItem method of JComboBox takes an Object as an input so you could pretty much try adding JCheckBox to it.

verruckt24
Posting Shark
952 posts since Nov 2008
Reputation Points: 485
Solved Threads: 89
 
The addItem method of JComboBox takes an Object as an input so you could pretty much try adding JCheckBox to it.

ok....will try this, let's see what happens

SSagar
Newbie Poster
13 posts since Mar 2009
Reputation Points: 10
Solved Threads: 0
 

ComboBox will select only one item at the time and checkBoxes are used when user is allowed to select multiple items which contradicts the use of ComboBox.

I think the initiator needs to rethink about the use of checkbox in comboBox.

JComboBox only displays the results from a call to the object's toString() method. I suppose you have to alter the renderer that the combobox uses to display the items. Have a look at this link http://forums.sun.com/thread.jspa?forumID=57&threadID=5198095

borntowin
Newbie Poster
1 post since Mar 2009
Reputation Points: 10
Solved Threads: 0
 

ComboBox will select only one item at the time and checkBoxes are used when user is allowed to select multiple items which contradicts the use of ComboBox.

I think the initiator needs to rethink about the use of checkbox in comboBox.

All this was already said. Read the previous posts before posting yours.

verruckt24
Posting Shark
952 posts since Nov 2008
Reputation Points: 485
Solved Threads: 89
 

Yes, you can do it with a custom renderer - I've dome something similar myself.

JamesCherrill
Posting Genius
Moderator
6,373 posts since Apr 2008
Reputation Points: 2,130
Solved Threads: 1,073
 
Yes, you can do it with a custom renderer - I've dome something similar myself.


Hi... am doing this using renderers and editors...its half done. Its giving some stackoverflow error.
hey plz help me in doing this.

SSagar
Newbie Poster
13 posts since Mar 2009
Reputation Points: 10
Solved Threads: 0
 

Print out the entire error trace for us here.

verruckt24
Posting Shark
952 posts since Nov 2008
Reputation Points: 485
Solved Threads: 89
 
Print out the entire error trace for us here.

Error:
java.lang.StackOverflowError
java.lang.StackOverflowError
java.lang.StackOverflowError

SSagar
Newbie Poster
13 posts since Mar 2009
Reputation Points: 10
Solved Threads: 0
 

C'mon now I said we would need the entire stack trace, line number, file etc. Also post the relevant code with that without which we ould have no clue whatsover.

verruckt24
Posting Shark
952 posts since Nov 2008
Reputation Points: 485
Solved Threads: 89
 
C'mon now I said we would need the entire stack trace, line number, file etc. Also post the relevant code with that without which we ould have no clue whatsover.

This problem has been sorted out. Now am able to put checkbox in combo but not able to select the checkbox.

SSagar
Newbie Poster
13 posts since Mar 2009
Reputation Points: 10
Solved Threads: 0
 

You're probably going to have to dig into the event processing code of the combo and forward the appropriate events along to the checkbox that is being selected.

Ezzaral
Posting Genius
Moderator
15,986 posts since May 2007
Reputation Points: 3,250
Solved Threads: 847
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You