当我在列表中选择一个新项目时,我想多次更改我的JLabel文本,而不会覆盖它自己。
list.addMouseListener(new MouseListener() {
public void mouseReleased(MouseEvent e) {}
public void mousePressed(MouseEvent e) {}
public void mouseExited(MouseEvent e) {}
public void mouseEntered(MouseEvent e) {}
public void mouseClicked(MouseEvent e)
{
/**
* Create a JLabel which shows the selected item.
*/
String item = (String) list.getSelectedValue();
JLabel itemName = new JLabel(item);
itemName.setBounds(400, 50, 300, standardBtnHeight);
panel.add(itemName);
System.out.println("Showing: " + item);
revalidate();
repaint();
}
});
我只想让JLabel一次显示一个项目,但当我选择一个新项目时,它只会将新项目名称放在现有名称的顶部。当你选择了足够多的项目时,它只是一个黑条。感谢
谨致问候,品牌
list.addMouseListener(new MouseListener() {
public void mouseReleased(MouseEvent e) {
itemName.setText("text");
}
public void mousePressed(MouseEvent e) {
itemName.setText("text");
}
public void mouseExited(MouseEvent e) {
itemName.setText("text");
}
public void mouseEntered(MouseEvent e) {
itemName.setText("text");
}
public void mouseClicked(MouseEvent e) {
itemName.setText("text");
}
});