我构建了自己的SpinnerCellEditor,以便在我的表中使用它(Java 8)。技术上微调器工作正确,但微调器中的字体太小,无法读取。有谁知道如何解决这个问题?
编辑器的实施
public class BSSpinnerCellEditor extends AbstractCellEditor implements TableCellEditor {
private JSpinner inputField;
private final static double min = 0.0;
private final static double max = 5.0;
private final static double step = 0.5;
public BSSpinnerCellEditor () {
inputField = new JSpinner (new SpinnerNumberModel (0.0, min, max, step));
inputField.setOpaque (true);
inputField.setBorder (null);
} // EOConstructor
public BSSpinnerCellEditor (float actValue) {
if (actValue < 0.0f || actValue > 5.0f)
actValue = 0.0f;
inputField = new JSpinner (new SpinnerNumberModel ((double) actValue, min, max, step));
inputField.setOpaque (true);
inputField.setBorder (null);
}
public BSSpinnerCellEditor (SpinnerModel aModel) {
inputField = new JSpinner (aModel);
inputField.setBorder (null);
}
public Component getTableCellEditorComponent (JTable table,
Object value, boolean isSelected,
int row, int column) {
TableModel aModel = table.getModel ();
if (aModel != null && aModel instanceof BookRatingCriterionTableModel) {
BookRatingCriterionTableModel tModel = (BookRatingCriterionTableModel) aModel;
RatingCriterion aCriterion = tModel.getRatingCriterionAt (table.convertRowIndexToModel (row));
inputField.setValue (aCriterion.getRating ());
} // EOIf
return inputField;
}
public Object getCellEditorValue () {
float retVal = ((Double) inputField.getValue ()).floatValue ();
if (retVal < min) {
inputField.setValue (min);
retVal = ((Double) min).floatValue ();
}
else {
if (retVal > max) {
inputField.setValue (max);
retVal = ((Double) max).floatValue ();
}
}
return retVal;
}
}
与表的绑定
TableColumnModel aBookRatingModel = tab_Rat_Rating.getColumnModel ();
aBookRatingModel.getColumn(2).setCellEditor (new BSSpinnerCellEditor ());
结果如
我的Combobox单元格编辑器遇到了同样的问题。我通过将border属性设置为null来解决这个问题。但这不适用于此。我搜索了一个解决方案或类似的问题,但一无所获。
我将被要求提供任何信息或提示。
最好的问候 约尔格答案 0 :(得分:0)
祝你好运 约尔格