Why is my JTable CellRenderer working all the time?

// newbie question

I have a JTable with an almost basic cell renderer (it colors the line differently). I noticed that my cell rendering constantly works for rows displayed on the screen, even if I am not doing anything with the table.

Is that how it should be? Wasn't it supposed to do each cell once and what is it? How can I make him stop and only recount the changes?

public Component getTableCellRendererComponent(JTable table, Object value,
    boolean isSelected, boolean hasFocus, int row, int column) {

   log.debug("Building cell : " + row + "," + column);

   Component comp = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);

   Filter filter = (Filter)table.getModel().getValueAt(row, Column.CLASSIFICATION.getIndex());
   comp.setBackground(filter.getColor());
   return comp;

  }
+3
source share
4 answers

JTables, . 99,9% Java- . , : , , .

JTables, Sun :

" , JTables, "

, " ", JTable perfs , :

()

(Oracle)

:

, , JTable-, , (, , GC ).

+1

@Steve McLeod, , , CellRenderers

@Override
    public Component getTableCellRendererComponent(JTable table, Object value,
            boolean isSelected, boolean hasFocus, int row, int column) {

        log.debug("Building a list for " + row + "," + column);
        setListData(((Vector<String>)value).toArray());     
        setToolTipText("This is a tool tip for " + row + "," + column);

        table.setRowHeight(row, Math.max(1, getPreferredSize().height));
        Filter filter = (Filter)table.getModel().getValueAt(row, Column.CLASSIFICATION_RESULT.getIndex());
        setBackground(filter.getColor());       
        return this;
    }

:

table.setRowHeight(row, Math.max(1, getPreferredSize().height));

, ... .

+3

, . - 1 2, , ​​. , - .

+1
source

rendering already caches your processed component, when nothing changes, it does not receive anything again.

However, when the table discovers something that has changed, it will request a re-render. The event that triggers it the most is mouse movement.

So yes, this is normal behavior for JTable.

0
source

Source: https://habr.com/ru/post/1782282/


All Articles