use*_*430 0 java swing combobox jcombobox
下面的代码用于根据所选日期使用可用时间填充组合框.
但是由于某种原因,组合框正在存储数据示例的内存地址:
Restaurant.Time@1a28362
Restaurant.Time@5fcf29
...
Run Code Online (Sandbox Code Playgroud)
我知道它得到了正确的时间.但是,我如何实际打印出实际物品?
TimeList times = dbConnector.selectTimes(lblDay.getText());//lblDay stores the date from the jCalendar button
cmbNewResTimes.removeAllItems();
for (int pos1 = 0; pos1 < times.size(); pos1++) {
cmbNewResTimes.addItem(times.getTimeAt(pos1).toString());
}
Run Code Online (Sandbox Code Playgroud)
首先,将其更改为:
// add the Object, rather than the String representation.
cmbNewResTimes.addItem(times.getTimeAt(pos1));
Run Code Online (Sandbox Code Playgroud)
然后设置渲染器,请参阅:
JComboBox.setRenderer(ListCellRenderer)