What are the differences between ComboBox and ChoiceBox in JavaFX? I'm not entirely clear on that just from the Javadoc for both classes.
At the end of the day, I need a dropdown control that can be repopulated dynamically at runtime (I've got a database on the backend). For all cases in my application, I only need to select one item from the dropdown menus. The user also shouldn't be able to add an option to the dropdown menu from the screens they are visible on.
My understanding is that ComboBox allows the user to add items to the dropdown list and allows for selecting multiple items, but from the Javadoc it seems like it's possible to setup ComboBox in a way that meets my needs, so it seems like they're interchangeable to some extent. I guess ComboBox has a bit more overhead than I really need in this case, but is there anything else that only a ComboBox could do that would factor into this decision?
Edit
I guess I kind of answered my own question on the key differences, so is there something else I've not mentioned that differentiates the 2?
ComboBox supports a cellFactory which allows essentially an arbitrary UI for displaying the item in each cell. ChoiceBox does not have this functionality and will only display text in each cell (which you can configure using a converter).
See http://docs.oracle.com/javase/8/javafx/user-interface-tutorial/combo-box.htm#BABJCCIB listing 16.5 for an example of a custom cell factory in a combo box.
Well ChoiceBox is of the idea showing you optional choices, and ComboBox well shows you a list of items, ChoiceBox is like ComboBox but ComboBox is for a really lengthy list as you can specify the number of items to display like 10 or more or less, but ChoiceBox does not have the option it list all options and if its very long you wouldn't like the look.
in short ChoiceBox, for small set of list less than 10, for more ComboBox
That is from my perspective the difference, as for styling you can style all.
Combo Box
A combo box is a typical element of a user interface that enables users to choose one of several options. A combo box is helpful when the number of items to show exceeds some limit, because it can add scrolling to the drop down list, unlike a choice box. If the number of items does not exceed a certain limit, developers can decide whether a combo box or a choice box better suits their needs.
Choice Box
This chapter describes choice boxes, the UI controls that provide support for quickly selecting between a few options.
http://docs.oracle.com/javafx/2/ui_controls/jfxpub-ui_controls.htm
We can simply differentiate ComboBox and ChoiceBox by their functionalities.Just have a look on deffintion.
The JavaFX ComboBox control enables users to choose an option from a predefined list of choices, or type in another value if none of the predefined choices matches what the user want to select.
The JavaFX ChoiceBox control enables users to choose an option from a predefined list of choices only.
Apart from the mentioned differences:
ComboBox can show a prompt with setPromptText (ChoiceBox doesn't provide that method)
ComboBox can show more than 10 rows with setVisibleRowCount (ChoiceBox doesn't provide that method)
I'm doing a program in JavaFX with ComboBoxes, and loading a FXML for the layout.
When I click for the first time in a ComboBox with few items (only two, for example), the scrollbar is shown at the right side. After I open it again, the scrollbar doesn't appear anymore.
I tried some solutions. One that worked is to apply a CSS directly in the FXML, which sets the cell size to a fixed value. But a solution inside the code (for example, in the initialize function in the controller) would be better for my case.
Thanks for any help.
This problem seems to be fixed in recent JDK versions, see https://bugs.openjdk.java.net/browse/JDK-8095019
If the options would stay fixed I would suggest using ChoiceBox instead of ComboBox. It is basically the same, but without the scrollable option. If you insist using ComboBox you can try combobox.setVisibleRowCount()
Is there any way that I can make the suggestions box wider without actually changing the width of that jtable column? I want to make the suggestion box wider than the actual jcombobox.
The standard way is to use the JComboBox.setPrototypeDisplayValue() method; ideally you'd pass in the longest item so that the combobox can set a good default width.
This is briefly touched upon in the GlazedLists Developer Tutorials; see "AutoCompleteSupport Screencast" for the walkthrough.
I have a touchscreen interface that I have adjusted the tab, button, and scrollsize but I am uncertain if it is possible to make JComboBox easier to select individual items. Is there someplace that I can find a list of all the UIManager attributes that can be changed with put?
This is what you're looking for:
http://tips4java.wordpress.com/2008/10/09/uimanager-defaults/
You may need to set your own ListCellRenderer. It doesn't seem to have anything to change the default height.
I need to create a ComboBox in Java that will have information in a column on the left and a Checkbox in a column on the right so that a user can select multiple items in the ComboBox. This needs to be a ComboBox because there could be 100 items in the list that may need to be checked but they cannot take up much space on the user interface.
Does anyone know how to do this?
Using a JList inside a JScrollPane seems more appropriate for dealing with that many items. It supports the standard CTRL-click to select multiple items.
A multi-selection combobox with 100 items sounds like a UI nightmare.