Difference in JComboBox and JSpinner

I am writing a Java Desktop utility in Java swing and have a minimal part of the GUI in it, most of the work is done on the server side, that is, on the backend. Thus, I do not want to spend a lot of time on a part of the GUI, studying different controls and widgets. The problem is that Swing has two controls for (for me) the same tasks, i.e. drop-down menu, and they are JComboBox and JSpinner I do not know the difference, and I do not want any restrictions that would prevent me from completing mine after I selected it.

I have to use the drop-down list to display the List<String> returned from the DataBase, and can have up to a thousand values. So that the user does not start scrolling, I will enter an alphabetic alphabet as input or some kind of category restriction will be like this, so it may be that I will use certain values โ€‹โ€‹to display from List<String> . I want my program to be as effective as possible and spend less time in the foreground, since there are many operations on the backend.

Any help would be greatly appreciated

+8
java swing jcombobox jspinner
source share
3 answers
  • you're talking about JComboBox / JTextField startup

  • with some effort one could apply ( AutoComplete JTextField ) to JSpinner too

I have to use the drop-down list to display the list returned from the database, and can have up to a thousand values.

  • all of the above JComponents are based on a premature array, you may need to convert java.util.List to String[] or Vector (depends on your code logics)

  • none of the GUIs are designed to support thousands of values, see Paginations for Databases engine

  • the aforementioned AutoComplete JComboBox / JTextField works without any problems up to 2 thousand lines on today's PC

  • for a search or selection from the largest arrays you see Stepped JComboBox (about two or more JComboBoxes )

    1.st for a smaller selection from [0-9, AZ]

    2.nd for searching started entries with A (for example)

  • redirect Database events to background tasks and use SwingWorker or Runnable#Thread

+4
source share

The main difference is in the model: the SpinnerModel implementation creates a sequence of values, but the ComboBoxModel does not. If the objects in SpinnerModel do not have a suitable natural order, you will need to overlay one.

As a practical question, โ€œthousands of meaningsโ€ will be useful from a supportive approach, as suggested by @mKorbel's answer .

+4
source share

JComboBox meets your requirement. JComboBox is suitable for displaying a list of values. JSpinner is used when you want to perform some functions, such as incerement / decment in the Spinner text box.

This Oracle tutorial explains JSpinner and its similarities to JComboBox . There is also a demo application.

+2
source share

All Articles