Change the background color of a JTextArea [duplicate]

0

I'm a beginner in Java and I'm trying to create a function that changes the background of the words, I took a print of the example I'd like it to look like. The expected one is that in a table example, but the separation is by comma. If anyone can help me, thank you in advance.

    
asked by anonymous 28.04.2016 / 17:44

1 answer

0

In order to give a table effect, you will have to create a class that will inherit DefaultTableCellRenderer and overwrite method getTableCellRendererComponent

You can do as in the example below, in that it changes beyond the background, border and font.

private class TableRowHeaderCellRenderer extends DefaultTableCellRenderer {
 @Override
  public Component getTableCellRendererComponent(
                    JTable table, Object value, boolean isSelected,
                    boolean hasFocus, int row, int column) {
        setFont(new java.awt.Font("Arial Black", 0, 21 ));
        setBorder(new SoftBevelBorder(SoftBevelBorder.RAISED));
        setBackground(new Color(244, 242, 228));
        setValue((String) value);
        return this;
    }
}
    
28.04.2016 / 18:02