Jcombobox with Jcheckboxes - java

how can I create (with JAVA) Combobox that contains Checkboxes for multiple selection and display the selected items in the Combobox like this picture:
click to see the pic
and thnx for advance.
EDIT:
I found this API (JAPURA API) and it's great but when I select multiple things I want to display the selected items instead of "* multiple items *".

Here's the link to achieve your goal:
JComboBox Providing a Custom Renderer

I would suggest you create a JButton and style it in the form of a Combobox if you want that.
Then, at the onclick function (actionperformed), you create a JPanel and make it visible under the button. In the panel, you can put whatever you want, so you just put checkboxes there.
I know this is kind of a workaround of your problem, but it should be easy for you to do so, and the actual user does not see a difference at all.
Hope I could help you.
Cheers,
Lucky

Related

Nested JComboBoxes in Java

I've created a JComboBox and when I choose an option from the combo box I want to add another combo box (for choosing more specific details) for the selected option. Is this possible?
I've tried creating another JComboBox in the original combo box's actionPerformed class, but I didn't solve the problem.
The result should look something like this:
Regarding adding a new JComboBox: Rather than actionPerformed try with JComboBox.addItemListener(ItemEvent). This is the right place to get the selected item and therefore to create and populate a new JComboBox with details you want to include.
Here a link to a demo project in GitHub

Can I add to Combobox's model a different value than String?

I've created a Java Application Project in Netbeans. This project has the main class JFrame form. There is, inter alia, Combo Box. I need to add a quadratic function to this Combobox. And I really don't want to use for squared anything like this
^2 .
I've thought, that function might be represented by ,for example, .png file.(Like setting icon of buttons).
Is it possible to add a picture to the model of Combo Box?
Can be model of Combobox different than String?
Or any idea, how to add a function to the Combo Box without ^ or _ ?
I have this idea for few days, but I really don't know how to solve this.
The short answer is "yes".
The responsibility for displaying the value in the combo box comes down to the ListCellRenderer
Take a look at How to use Combo Boxes for details and Providing a Custom Renderer for specifics
Image from How to use Combo Boxes trail
Of course, how you achieve this is entirely up to you. I would encourage you to put something easily identifiable in the model and then let the renderer figure out how to render it. This is kind of important as you will need to know what the user has selected and identify it at some stage, and an Image might not be the best solution for this.

Working with radio button in java

I've two jRadioButtons in Java application. Let's say Male and Female. Initially one is selected. While selecting another, the previous should be unselected and vice-versa. How to make it work? Also how can it be used to store in database?
You can give same name to all the radio buttons, from which you want to select only one. That way, you will be able to select just one button out of all. This you can do by creating a ButtonGroup.
Now, if you want to add the selected item to the database, just get the value corresponding to the name of Button Group, you will get the value of selected button.
See documentation and tutorial
What you need to use is a ButtonGroup component. Have a look at: How to Use the ButtonGroup Component

how to set text to a jcombobox, but the text set should not be an element of jcombobox

is their any way to set text for a combo box, which is not an element of the combobox.
cboSubjects=new JComboBox();
cbo.addItem("Maths"); // and few more subjects are added
cbo.setSelectedItem("subjects"); // this does not set the default text of combobox
Is their any way to solve this problem ? I need something which works like combobox.text
property of combobox in visual basic
I am working on school management system. I need help.
I'd like to show you a possible alternative :)
Note, you need to call label.setDisplayedMnemonic('s'); and label.setLabelFor(combo) to complete the effect!
You can make jComboBox editable, cbo.setEditable(true);, and after that set the text you want: cbo.setSelectedItem("subjects");

How to prevent JComboBox from closing?

After selecting an item from a JComboBox, i want to keep the JComboBox still opened to allow the user to choose another item from it. Is that possible ?
I hope you can provide me an example.
Perhaps what you are after is a JList instead.
As a different approach, maybe you can display in the JComboBox only the "allowed to choose" items in first place?

Categories