Ask Me Help Desk

Ask Me Help Desk (https://www.askmehelpdesk.com/forum.php)
-   Java (https://www.askmehelpdesk.com/forumdisplay.php?f=440)
-   -   Java Swing Problem (https://www.askmehelpdesk.com/showthread.php?t=28837)

  • Jul 4, 2006, 01:35 AM
    guyshahar
    Java Swing Problem
    A JComboBox has constructors that can take a Vector or a ComboBoxModel.

    When I pass a DefaultComboBoxModel to it, and change the contents of the DefaultComboBoxModel, the drop-down list changes as expected. No problem.

    However, if I pass a Vector to it and change the contents of the Vector, the drop-down list goes blank. It is still there, because if I click on any point in the blank space, the most recent option is called and the list is then visible.

    I have tried calling validate() on the JComboBox, but it makes no difference.

    I want to experiment with generics, and cannot do so with DefaultComboBoxModel. Can anybody tell me a simple way to use Vectors in Swing without weird results??
  • Jul 5, 2006, 01:12 AM
    LTheobald
    I missed this one yesterday. I'll try and recreate the problem myself some time today.

    In the meanwhile let me know what JDK you are using in case that makes a difference.
  • Jul 5, 2006, 01:29 AM
    guyshahar
    Thanks. It's the 5.0 JDK for Windows.

    Somebody proposed a solution to me that seems to work. They told me that having updated the Vector, I need to add the line:

    ComboBox.setModel(new DefaultComboBoxModel(vector));

    And this updates the drop-down list.

    Strange that without this line, the list updates eventually, but is initially blank...

  • All times are GMT -7. The time now is 07:31 AM.