使用JTable行高的增加或减少来调整JTable fontSize的大小

时间:2016-10-18 12:28:09

标签: java swing jtable

我正在尝试通过更改JTable的行高来调整字体大小。表的行高可在application.properties文件中配置,因此每次应用程序启动时,它都会获得配置的行高并呈现表。

现在行高已根据application.properties文件中提供的设置进行了更改但是......

问题是:如果行高度发生变化,每个单元格的字体大小都不会更新,如果我增加属性文件中的设置,则只会增加行高。

我正在尝试在表的构造函数中实现此更改,以便通过提供的配置实例化新实例。

public class CustomTable extends JTable 
{
    . . . 
    . . .


    public CustomTable(String name, User user, boolean isOffice) {
        this(name, user != null && user.isPermissed("ALLOW_GRID_RESIZE", "Terminal"), isOffice);
        this.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS);
        this.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
        if(!isOffice)
        {
            // This change is getting rendered
            this.setRowHeight(ApplicationSettings.getTableRowHeight());

            // For some reason these changes aren't getting rendere
            Font font = this.getFont();
            font = font.deriveFont(((float) (font.getSize2D() * (1 + ApplicationSettings.getTableRowHeight()/100))));
            this.setFont(font);         
        }
    }
    . . .
    . . .
}

0 个答案:

没有答案
相关问题