JComboBox下拉框的下拉选项过长,达到了40多个选项,一次性全部显示出来了。
我只想让它最大的显示 10行,brandComboBox.setMaximumRowCount(10); 这样设置都没有影响。
因为用到了mac的风格包 ,受了它的影响,改不了。有什么其他的方式可以改变这个长度吗?
我只想让它最大的显示 10行,brandComboBox.setMaximumRowCount(10); 这样设置都没有影响。
因为用到了mac的风格包 ,受了它的影响,改不了。有什么其他的方式可以改变这个长度吗?
public void changeModelValue(Device parentDevice) {
brandList = new ArrayList<BrandBean>();
List<String> brandIds = new ArrayList<String>(); String device_Type = parentDevice.getDeviceType();
newEditPrecodePanel.brandComboBox.setMaximumRowCount(15); //我在这里设置了它的最大长度都么用 if (null == PrecodeDeviceStore.getDeviceBrandIdList()) {
newEditPrecodePanel.brandComboBox.addItem(null);
return;
}
if (null == PrecodeDeviceStore.getBrandList()) {
newEditPrecodePanel.brandComboBox.addItem(null);
return;
}
brandList.add(new BrandBean("-1", " All "));
for (DeviceBrandBean elem : PrecodeDeviceStore.getDeviceBrandIdList()) {
if (device_Type.equals(elem.getDeviceType().trim())) {
brandIds.add(elem.getBrandId() + "");
}
}
if (brandIds.size() == 0) {
newEditPrecodePanel.brandComboBox.addItem(null);
return;
}
for (String id : brandIds) {
for (BrandBean elem : PrecodeDeviceStore.getBrandList()) {
if (id.trim().equals(elem.getBrand_id().trim())) {
brandList.add(elem);
}
}
}
if (null == brandList || brandList.size() == 0) {
newEditPrecodePanel.brandComboBox.addItem(null);
return;
} //设置Brand
Collections.sort(brandList);
for (BrandBean brand : brandList) {
newEditPrecodePanel.brandComboBox.addItem(brand.getBrand_name()); //这是是把数据添加到JComboBox(brandComboBox)
}
}
我项目里的JCombox都是使用默认的 没有设置过什么 但是当我添加许多内容进去的时候 当它增加到8行的时候 就会自动开始出现下拉条 再添加就都需要往下拉才能看见了