表中的微调文本太小了

问题描述 投票:0回答:1

我构建了自己的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 ());

结果看起来像

Result

我的Combobox单元格编辑器遇到了同样的问题。我通过将border属性设置为null来解决这个问题。但这不适用于此。我搜索了一个解决方案或类似问题,但一无所获。

我将不得不提供任何信息或提示。

最好的问候Joerg

java fonts spinner
1个回答
0
投票

问题是,微调器大于行高,因此唯一的方法是扩大行高。因为微调器的高度取决于外观,我使用一个变量,该变量将使用微调器的首选大小进行设置,该变量在第一个表之前初始化,然后设置表的正确行高。我知道这只有效,因为微调器在表之前被初始化。但我找不到其他解决方案来解决这个问题。我希望这也能帮助别人。

最好的问候Joerg

© www.soinside.com 2019 - 2024. All rights reserved.