简体   繁体   中英

Spinner text in table too small

I build my own SpinnerCellEditor for using it in my tables (Java 8). Technical the spinner works correct, but the font in the spinner is so small, that it can not be read. Does anyone has an idea how to solve this problem?

The implementation of the Editor

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;
} 

}

The binding to the table

TableColumnModel aBookRatingModel = tab_Rat_Rating.getColumnModel ();

aBookRatingModel.getColumn(2).setCellEditor (new BSSpinnerCellEditor ());

The result looks like

Result

I had the same problem with my Combobox cell editor. I solved this by setting the border attribute to null. But this does not work here. I searched for a solution or similar problems, but found nothing.

I would be obliged for any information or tip.

best regards Joerg

the problem is, that the spinner is bigger than the row height, so that the only way is, to enlarge the row height. Because the height of the spinner depends on the look and feel, I use a variable that will be set with the preferred size of a spinner, that is initialized before the first table and then set up the correct row height of the table. I know that this only works because the spinner is initialized before the table. But I found no other solution to solve this. I hope this will help others too.

Best regards Joerg

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM