使用另一个JComboBox中的选择填充JComboBox

时间:2017-04-07 10:06:23

标签: java list object jcombobox

我有2个JComboBoxes,其中一个显示ObjectsCategory(每个Category包含一个唯一的List),另一个显示{ {1}}中的{1}}。

目的是允许用户在第一个List中选择Category,然后使用适合用户选择的Category填充第二个JComboBox。< / p>

我的当前代码在用户选择之前显示JComboBox List JComboBox类型的Objects。第二个显示Category中的List没关系。但是在用户选择时,第二个Object没有做任何事情。在用户选择之前,它会继续显示相同的JComboBox

这是我的代码..

list

1 个答案:

答案 0 :(得分:1)

我认为您应该在包含类型editItemCatComboBox的第一个JCombobox Category上实现ItemListener,这样您每次选择新的Category时都可以更新第二个editItemCatComboBox.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent arg0) { //Update the second JCombobox } });

var map;
var infoWindow;

google.maps.event.addDomListener(window, "load", function () {

   initMap();

   var retVals = [{lat:33.808678, lng:-117.918921}, {lat:33.708378, lng:-117.918920}, {lat:33.700378, lng:-117.917920}];
   callbackAjax(retVals, map);
});

function initMap(){
  map = new google.maps.Map(document.getElementById("map_div"), {
    center: new google.maps.LatLng(33.808678, -117.918921),
    zoom: 10,
    mapTypeId: google.maps.MapTypeId.ROADMAP
  });
 infoWindow = new google.maps.InfoWindow();
}

function callbackAjax(returnValue, map){

  for(var i=0; i<returnValue.length; i++) {
     createMarker(map, returnValue[i].lat, returnValue[i].lng, "<h1> test"+ i + "</h1><p>content</p>");
   }

   function createMarker(map, lat, lng, content){
     var marker = new google.maps.Marker({
        map: map,
        position: new google.maps.LatLng(lat, lng),
        title: 'title'+i,
     });
     google.maps.event.addListener(marker, 'click', function() {
        infoWindow.setContent(content);
        infoWindow.open(map, this);
     });
     return marker;
    }
}
相关问题