-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCustomTableCellRenderer.java
More file actions
45 lines (40 loc) · 2.05 KB
/
CustomTableCellRenderer.java
File metadata and controls
45 lines (40 loc) · 2.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
*/
package com.mycompany.homeworktracker;
/**
*
* @author Sara Gebara
*/
import javax.swing.*;
import javax.swing.table.DefaultTableCellRenderer;
import java.awt.*;
//Creating class CustomTableCellRenderer which extents DefaultTableCellRenderer
//DefaultTableCellRenderer is a class in the Swing library used to render cells in a JTable
//Its functionalities include manipulating visual aspects, such as font color
public class CustomTableCellRenderer extends DefaultTableCellRenderer {
private Color fontColor; //Color variable to store the custom font color
//Constructor that takes a color fontColor as a parameter
public CustomTableCellRenderer(Color fontColor) {
this.fontColor = fontColor; //Sets font color based on parameter passed of user's choice
}
//Override the getTableCellRendererComponent method from DefaultTableCellRenderer so that this code is run
@Override
//Renders the contents of a cell in a table
//Parameters:
//table: the JTable asking the renderer to render
//value: the value of the cell being rendered
//isSelected: whether or not the cell is selected
//hasFocus: whether or not the cell has focus
//row: index of row being rendered
//column: index of column being rendered
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
//Calls the superclass to use its implementation of method getTableCellRendererComponent, passing this method's parameters to that method
super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
//Set the font color of the cell to the fontColor passed as a parameter
setForeground(fontColor);
//Return the configured renderer component
return this;
}
}