Answers for "set color of columns in jtable"

1

jtable set column background color

table.getColumn("Column title").setCellRenderer(
                new DefaultTableCellRenderer() {
            @Override
            public Component getTableCellRendererComponent(JTable table,
                    Object value, boolean isSelected, boolean hasFocus, int row, int col) {

                super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, col);

                Float quantityRemaining = (Float) table.getModel().getValueAt(row, col);
                    if (quantityRemaining < 1) {
                        setBackground(table.getBackground());
                        setForeground(Color.RED);
                        setToolTipText("This item needs immediate restocking!!!");
                    } else {
                        setBackground(table.getBackground());
                        setForeground(table.getForeground());
                        setToolTipText("Resonable stock quantities");
                    }
                return table;
            }
        });
    }
Posted by: Guest on April-22-2021

Code answers related to "set color of columns in jtable"

Browse Popular Code Answers by Language