gpt4 book ai didi

listCellRenderer 内的 java jcombobox

转载 作者:行者123 更新时间:2023-12-02 00:08:33 24 4
gpt4 key购买 nike

我想创建一个包含带有数据和 jCombobox 的项目的列表。我使用这个 listCellRenderer :

public class DeliveryListCellRenderer extends JPanel implements ListCellRenderer{

JLabel[] lbl = new JLabel[2];
JComboBox combo;

public DeliveryListCellRenderer()
{
setLayout(new GridLayout(0,2,15,0));
lbl[0] = new JLabel("",JLabel.RIGHT);
add(lbl[0]);
lbl[1] = new JLabel("",JLabel.LEFT);
add(lbl[1]);
String[] timeZones = {"timeZone 1", "timeZone 2", "timeZone 3", "timeZone 4"};

combo = new JComboBox(timeZones);
combo.setSelectedIndex(1);

add(combo);
}
public Component getListCellRendererComponent(JList list,Object value,
int index,boolean isSelected,boolean cellHasFocus)
{
Delivery delivery = (Delivery)value;
lbl[0].setText("X : "+delivery.getNode().getX());
lbl[1].setText("Y : "+delivery.getNode().getY());
if(isSelected) setBackground(Color.CYAN);
else setBackground(Color.WHITE);
return this;
}
}

当我运行应用程序时,一切都显示正常,但当我单击组合框时没有任何反应。

有人有想法吗?提前致谢。

最佳答案

When I run the application, everything appears ok, but nothing happens when I click on the combobox.

关于listCellRenderer 内的 java jcombobox,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13357603/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com