I need to update an icon in JTable
after the user digit a number in a JTextField
.
Step-by-Step:
- The user clicks in a
JTable
row, and after that, opens aJFrame
to edit its contents. - There is a
JTextField
in thatEditFrame
where the user put a number from 0 to 100. That number will change the icon being displayed in my JTable row after the user closeEditFrame
.
I read the documentation here.I changed my aproach.I killed the renderer and created static Icons in my Meal class and created a method like that:
public ImageIcon getIconByValue(int value){
if(value==0)
return ONESTAR;
else
return ...;
}
and made some changes in my tablemodel(to store a ImageIcon):
public Class<?> getColumnClass(int columnIndex) {
switch (columnIndex) {
case RATING:
return ImageIcon.class;
...}
public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
//..other cases....//
case RATING:
meal.getIconByValue((int)aValue);
break;
}
public void setData(List<Meal> list){
this.meals.clear();
for(Meal m:list){
Meal meal=new Meal();
//...other sets..//
meal.getIconByValue(m.getRating());
}
this.meals.add(meal);
}
But my Rating space(where should show the stars), is totally blank.
Note: I read other topics too, but none of the helps how to change icons OnTheFly in a JTable
.