如何根据单个单元格包含的值更改单个单元格的颜色?
根据我发现的内容,这就是我所拥有的。
import java.awt.EventQueue;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.JFrame;
import java.awt.Dimension;
import javax.swing.JPanel;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import javax.swing.border.EmptyBorder;
import javax.swing.JMenuBar;
import javax.swing.JMenu;
import javax.swing.JMenuItem;
import javax.swing.JButton;
import javax.swing.JTable;
import javax.swing.JLabel;
import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableCellRenderer;
public class DriversSeason1 extends JLabel implements TableCellRenderer{
private JFrame frameSeason1Drivers;
static JTable tableSeason1Drivers = new JTable();
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
DriversSeason1 window = new DriversSeason1();
window.frameSeason1Drivers.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
MyRenderer myRenderer = new MyRenderer();
tableSeason1Drivers.setDefaultRenderer(Object.class, myRenderer);
}
/**
* Create the application.
*/
public DriversSeason1() {
initialize();
}
/**
* Initialize the contents of the frame.
*/
private void initialize() {
frameSeason1Drivers = new JFrame();
frameSeason1Drivers.setBounds(100, 100, 780, 480);
frameSeason1Drivers.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel panelSeason1DriversFull = new JPanel();
panelSeason1DriversFull.setBorder(new EmptyBorder(5, 5, 5, 5));
frameSeason1Drivers.getContentPane().add(panelSeason1DriversFull, BorderLayout.CENTER);
panelSeason1DriversFull.setLayout(new BorderLayout(0, 0));
JPanel panelSeason1Drivers = new JPanel();
panelSeason1DriversFull.add(panelSeason1Drivers, BorderLayout.CENTER);
panelSeason1Drivers.setLayout(new BorderLayout(0, 0));
tableSeason1Drivers = new JTable();
tableSeason1Drivers.setBackground(Color.WHITE);
tableSeason1Drivers.setModel(new DefaultTableModel(
new Object[][] {
{"Pos", null, null, null, null, null, null, null, null, null, null, "", null, null, null, null, null, null, null, null, null, null, null, null, null, null},
{" 1", null, null, null, null, null, null, null, null, null, null, "", null, null, null, null, null, null, null, null, null, null, null, null, null, null},
{" 2", null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null},
{" 3", null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null},
{" 4", null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null},
{" 5", null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null},
{" 6", null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null},
{" 7", null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null},
{" 8", null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, "", null, null, null, null},
{" 9", null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null},
{"10", null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null},
{"11", null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null},
{"12", null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null},
{"13", null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null},
{"14", null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null},
{"15", null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null},
{"16", null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null},
{"17", null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null},
{"18", null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null},
{"19", null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null},
{"20", null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null},
{"21", null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null},
{"22", null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null},
{"Pos", null, null, null, null, null, null, null, null, null, null, "", null, null, null, null, null, null, null, null, null, null, null, null, null, null},
},
new String[] {
"New column", "New column", "New column", "New column", "New column", "New column", "New column", "New column", "New column", "New column", "New column", "New column", "New column", "New column", "New column", "New column", "New column", "New column", "New column", "New column", "New column", "New column", "New column", "New column", "New column", "New column"
}
));
tableSeason1Drivers.getColumnModel().getColumn(0).setPreferredWidth(21);
tableSeason1Drivers.getColumnModel().getColumn(1).setPreferredWidth(91);
tableSeason1Drivers.getColumnModel().getColumn(2).setPreferredWidth(23);
tableSeason1Drivers.getColumnModel().getColumn(3).setPreferredWidth(23);
tableSeason1Drivers.getColumnModel().getColumn(4).setPreferredWidth(23);
tableSeason1Drivers.getColumnModel().getColumn(5).setPreferredWidth(23);
tableSeason1Drivers.getColumnModel().getColumn(6).setPreferredWidth(23);
tableSeason1Drivers.getColumnModel().getColumn(7).setPreferredWidth(23);
tableSeason1Drivers.getColumnModel().getColumn(8).setPreferredWidth(23);
tableSeason1Drivers.getColumnModel().getColumn(9).setPreferredWidth(23);
tableSeason1Drivers.getColumnModel().getColumn(10).setPreferredWidth(23);
tableSeason1Drivers.getColumnModel().getColumn(11).setPreferredWidth(23);
tableSeason1Drivers.getColumnModel().getColumn(12).setPreferredWidth(23);
tableSeason1Drivers.getColumnModel().getColumn(13).setPreferredWidth(23);
tableSeason1Drivers.getColumnModel().getColumn(14).setPreferredWidth(23);
tableSeason1Drivers.getColumnModel().getColumn(15).setPreferredWidth(23);
tableSeason1Drivers.getColumnModel().getColumn(16).setPreferredWidth(23);
tableSeason1Drivers.getColumnModel().getColumn(17).setPreferredWidth(23);
tableSeason1Drivers.getColumnModel().getColumn(18).setPreferredWidth(23);
tableSeason1Drivers.getColumnModel().getColumn(19).setPreferredWidth(23);
tableSeason1Drivers.getColumnModel().getColumn(20).setPreferredWidth(23);
tableSeason1Drivers.getColumnModel().getColumn(21).setPreferredWidth(23);
tableSeason1Drivers.getColumnModel().getColumn(22).setPreferredWidth(23);
tableSeason1Drivers.getColumnModel().getColumn(23).setPreferredWidth(35);
tableSeason1Drivers.getColumnModel().getColumn(24).setPreferredWidth(42);
tableSeason1Drivers.getColumnModel().getColumn(25).setPreferredWidth(34);
panelSeason1Drivers.add(tableSeason1Drivers, BorderLayout.CENTER);
JMenuBar menuBar = new JMenuBar();
panelSeason1DriversFull.add(menuBar, BorderLayout.NORTH);
JMenu menuDrivers = new JMenu("Drivers Standings");
menuBar.add(menuDrivers);
JMenuItem menuItemSeason1 = new JMenuItem("Season 1");
menuDrivers.add(menuItemSeason1);
JMenuItem menuItemSeason2 = new JMenuItem("Season 2");
menuDrivers.add(menuItemSeason2);
JMenuItem menuItemSeason3 = new JMenuItem("Season 3");
menuDrivers.add(menuItemSeason3);
JMenuItem menuItemSeason4 = new JMenuItem("Season 4");
menuDrivers.add(menuItemSeason4);
JMenuItem menuItemSeason5 = new JMenuItem("Season 5");
menuDrivers.add(menuItemSeason5);
JMenuItem menuItemSeason6 = new JMenuItem("Season 6");
menuDrivers.add(menuItemSeason6);
JMenuItem menuItemSeason7 = new JMenuItem("Season 7");
menuDrivers.add(menuItemSeason7);
JMenuItem menuItemSeason8 = new JMenuItem("Season 8");
menuDrivers.add(menuItemSeason8);
JMenuItem menuItemSeason9 = new JMenuItem("Season 9");
menuDrivers.add(menuItemSeason9);
JMenuItem menuItemSeason10 = new JMenuItem("Season 10");
menuDrivers.add(menuItemSeason10);
JMenu menuConstructors = new JMenu("Constructors Standings");
menuBar.add(menuConstructors);
JMenuItem menuItemSeason1Con = new JMenuItem("Season1");
menuConstructors.add(menuItemSeason1Con);
JMenuItem menuItemSeason2Con = new JMenuItem("Season 2");
menuConstructors.add(menuItemSeason2Con);
JMenuItem menuItemSeason3Con = new JMenuItem("Season 3");
menuConstructors.add(menuItemSeason3Con);
JMenuItem menuItemSeason4Con = new JMenuItem("Season 4");
menuConstructors.add(menuItemSeason4Con);
JMenuItem menuItemSeason5Con = new JMenuItem("Season 5");
menuConstructors.add(menuItemSeason5Con);
JMenuItem menuItemSeason6Con = new JMenuItem("Season 6");
menuConstructors.add(menuItemSeason6Con);
JMenuItem menuItemSeason7Con = new JMenuItem("Season 7");
menuConstructors.add(menuItemSeason7Con);
JMenuItem menuItemSeason8Con = new JMenuItem("Season 8");
menuConstructors.add(menuItemSeason8Con);
JMenuItem menuItemSeason9Con = new JMenuItem("Season 9");
menuConstructors.add(menuItemSeason9Con);
JMenuItem menuItemSeason10Con = new JMenuItem("Season 10");
menuConstructors.add(menuItemSeason10Con);
JButton btnRacingRecord = new JButton("Racing Record");
menuBar.add(btnRacingRecord);
JButton btnStats = new JButton("Stats");
menuBar.add(btnStats);
JButton btnRaceInput = new JButton("Race Input");
menuBar.add(btnRaceInput);
}
@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus,
int row, int column) {
// TODO Auto-generated method stub
return null;
}
}
然后是应该改变背景颜色的渲染器类
import java.awt.Color;
import java.awt.Component;
import javax.swing.JTable;
import javax.swing.table.DefaultTableCellRenderer;
public class MyRenderer extends DefaultTableCellRenderer
{
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column)
{
Component c = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
if (((int)table.getValueAt(row, column)) == 1)
{
System.out.println("hi");
}
else
{
c.setBackground(table.getBackground());
}
return c;
}
}
答案 0 :(得分:3)
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
DriversSeason1 window = new DriversSeason1();
window.frameSeason1Drivers.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
MyRenderer myRenderer = new MyRenderer();
tableSeason1Drivers.setDefaultRenderer(Object.class, myRenderer);
}
main方法在单独的Thread上运行,因此您在创建DriversSeason1类之前尝试将渲染器添加到表中。
然后,当Event Dispatch Thread上的代码执行时,您的DriverSeason1类被创建,并且您创建了一个新的JTable,因此所有自定义渲染器都将丢失。
解决方案很简单。创建表时将渲染器添加到表中。
此外,您的DriversSeason1类不应扩展JLabel并实现TableCellRenderer。摆脱所有代码。
最后,当您修复这些问题时,渲染器中仍然会出现错误,这应该是显而易见的。您将数据作为String对象加载,因此您不能指望创建对象和Integer。您需要在代码中进行字符串比较,而不是整数比较。
答案 1 :(得分:-1)
你的代码有很多难闻的气味,如果你不知道怎么做得更好,我建议你阅读一些书,比如Refactoring:改进现有代码的设计和Effective Java。 无论如何,我做了它,请检查它是否是你想要的。
package self.examples;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.EventQueue;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.JTable;
import javax.swing.border.EmptyBorder;
import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableCellRenderer;
public class DriversSeason1 extends JLabel implements TableCellRenderer {
private JFrame frameSeason1Drivers;
static JTable tableSeason1Drivers = new JTable();
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
DriversSeason1 window = new DriversSeason1();
window.frameSeason1Drivers.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the application.
*/
public DriversSeason1() {
initialize();
}
/**
* Initialize the contents of the frame.
*/
private void initialize() {
frameSeason1Drivers = new JFrame();
frameSeason1Drivers.setBounds(100, 100, 780, 480);
frameSeason1Drivers.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel panelSeason1DriversFull = new JPanel();
panelSeason1DriversFull.setBorder(new EmptyBorder(5, 5, 5, 5));
frameSeason1Drivers.getContentPane().add(panelSeason1DriversFull, BorderLayout.CENTER);
panelSeason1DriversFull.setLayout(new BorderLayout(0, 0));
JPanel panelSeason1Drivers = new JPanel();
panelSeason1DriversFull.add(panelSeason1Drivers, BorderLayout.CENTER);
panelSeason1Drivers.setLayout(new BorderLayout(0, 0));
tableSeason1Drivers = new JTable();
tableSeason1Drivers.setBackground(Color.WHITE);
MyRenderer myRenderer = new MyRenderer();
tableSeason1Drivers.setDefaultRenderer(Object.class, myRenderer);
tableSeason1Drivers.setModel(new DefaultTableModel(
new Object[][] {
{ "Pos", null, 1, null, null, null, null, null, null, null, null, "", null, null, null, null,
null, null, null, null, null, null, null, null, null, null },
{ " 1", null, null, null, null, null, null, null, null, null, null, "", null, null, null, null,
null, null, null, null, null, null, null, null, null, null },
{ " 2", null, null, null, null, null, null, null, null, null, null, null, null, null, null,
null, null, null, null, null, null, null, null, null, null, null },
{ " 3", null, null, null, null, null, 1, null, null, null, null, null, null, null, null, null,
null, null, null, null, null, null, null, null, null, null },
{ " 4", null, null, 1, null, null, null, null, null, null, null, null, null, null, null, null,
null, null, null, null, null, null, null, null, null, null },
{ " 5", null, null, null, null, null, null, null, null, null, null, null, null, null, null,
null, null, null, null, null, null, null, null, null, null, null },
{ " 6", null, null, null, null, null, null, null, null, null, null, null, null, null, null,
null, null, null, null, null, null, null, null, null, null, null },
{ " 7", null, null, null, null, null, null, null, null, null, null, null, null, null, null,
null, null, null, null, null, null, null, null, null, null, null },
{ " 8", null, null, null, null, null, null, null, null, null, null, null, null, null, null,
null, null, null, null, null, null, "", null, null, null, null },
{ " 9", null, null, null, null, null, null, null, null, null, null, null, null, null, null,
null, null, null, null, null, null, null, null, null, null, null },
{ "10", null, null, null, null, null, null, null, null, null, null, null, null, null, null,
null, null, null, null, null, null, null, null, null, null, null },
{ "11", null, null, null, null, null, null, null, null, null, null, null, null, null, null,
null, null, null, null, null, null, null, null, null, null, null },
{ "12", null, null, null, null, null, null, null, null, null, null, null, null, null, null,
null, null, null, null, null, null, null, null, null, null, null },
{ "13", null, null, null, null, null, null, null, null, null, null, null, null, null, null,
null, null, null, null, null, null, null, null, null, null, null },
{ "14", null, null, null, null, null, null, null, null, null, null, null, null, null, null,
null, null, null, null, null, null, null, null, null, null, null },
{ "15", null, null, null, null, null, null, null, null, null, null, null, null, null, null,
null, null, null, null, null, null, null, null, null, null, null },
{ "16", null, null, null, null, null, null, null, null, null, null, null, null, null, null,
null, null, null, null, null, null, null, null, null, null, null },
{ "17", null, null, null, null, null, null, null, null, null, null, null, null, null, null,
null, null, null, null, null, null, null, null, null, null, null },
{ "18", null, null, null, null, null, null, null, null, null, null, null, null, null, null,
null, null, null, null, null, null, null, null, null, null, null },
{ "19", null, null, null, null, null, null, null, null, null, null, null, null, null, null,
null, null, null, null, null, null, null, null, null, null, null },
{ "20", null, null, null, null, null, null, null, null, null, null, null, null, null, null,
null, null, null, null, null, null, null, null, null, null, null },
{ "21", null, null, null, null, null, null, null, null, null, null, null, null, null, null,
null, null, null, null, null, null, null, null, null, null, null },
{ "22", null, null, null, null, null, null, null, null, null, null, null, null, null, null,
null, null, null, null, null, null, null, null, null, null, null },
{ "Pos", null, null, null, null, null, null, null, null, null, null, "", null, null, null, null,
null, null, null, null, null, null, null, null, null, null }, },
new String[] { "New column", "New column", "New column", "New column", "New column", "New column",
"New column", "New column", "New column", "New column", "New column", "New column",
"New column", "New column", "New column", "New column", "New column", "New column",
"New column", "New column", "New column", "New column", "New column", "New column",
"New column", "New column" }));
tableSeason1Drivers.getColumnModel().getColumn(0).setPreferredWidth(21);
tableSeason1Drivers.getColumnModel().getColumn(1).setPreferredWidth(91);
tableSeason1Drivers.getColumnModel().getColumn(2).setPreferredWidth(23);
tableSeason1Drivers.getColumnModel().getColumn(3).setPreferredWidth(23);
tableSeason1Drivers.getColumnModel().getColumn(4).setPreferredWidth(23);
tableSeason1Drivers.getColumnModel().getColumn(5).setPreferredWidth(23);
tableSeason1Drivers.getColumnModel().getColumn(6).setPreferredWidth(23);
tableSeason1Drivers.getColumnModel().getColumn(7).setPreferredWidth(23);
tableSeason1Drivers.getColumnModel().getColumn(8).setPreferredWidth(23);
tableSeason1Drivers.getColumnModel().getColumn(9).setPreferredWidth(23);
tableSeason1Drivers.getColumnModel().getColumn(10).setPreferredWidth(23);
tableSeason1Drivers.getColumnModel().getColumn(11).setPreferredWidth(23);
tableSeason1Drivers.getColumnModel().getColumn(12).setPreferredWidth(23);
tableSeason1Drivers.getColumnModel().getColumn(13).setPreferredWidth(23);
tableSeason1Drivers.getColumnModel().getColumn(14).setPreferredWidth(23);
tableSeason1Drivers.getColumnModel().getColumn(15).setPreferredWidth(23);
tableSeason1Drivers.getColumnModel().getColumn(16).setPreferredWidth(23);
tableSeason1Drivers.getColumnModel().getColumn(17).setPreferredWidth(23);
tableSeason1Drivers.getColumnModel().getColumn(18).setPreferredWidth(23);
tableSeason1Drivers.getColumnModel().getColumn(19).setPreferredWidth(23);
tableSeason1Drivers.getColumnModel().getColumn(20).setPreferredWidth(23);
tableSeason1Drivers.getColumnModel().getColumn(21).setPreferredWidth(23);
tableSeason1Drivers.getColumnModel().getColumn(22).setPreferredWidth(23);
tableSeason1Drivers.getColumnModel().getColumn(23).setPreferredWidth(35);
tableSeason1Drivers.getColumnModel().getColumn(24).setPreferredWidth(42);
tableSeason1Drivers.getColumnModel().getColumn(25).setPreferredWidth(34);
panelSeason1Drivers.add(tableSeason1Drivers, BorderLayout.CENTER);
JMenuBar menuBar = new JMenuBar();
panelSeason1DriversFull.add(menuBar, BorderLayout.NORTH);
JMenu menuDrivers = new JMenu("Drivers Standings");
menuBar.add(menuDrivers);
JMenuItem menuItemSeason1 = new JMenuItem("Season 1");
menuDrivers.add(menuItemSeason1);
JMenuItem menuItemSeason2 = new JMenuItem("Season 2");
menuDrivers.add(menuItemSeason2);
JMenuItem menuItemSeason3 = new JMenuItem("Season 3");
menuDrivers.add(menuItemSeason3);
JMenuItem menuItemSeason4 = new JMenuItem("Season 4");
menuDrivers.add(menuItemSeason4);
JMenuItem menuItemSeason5 = new JMenuItem("Season 5");
menuDrivers.add(menuItemSeason5);
JMenuItem menuItemSeason6 = new JMenuItem("Season 6");
menuDrivers.add(menuItemSeason6);
JMenuItem menuItemSeason7 = new JMenuItem("Season 7");
menuDrivers.add(menuItemSeason7);
JMenuItem menuItemSeason8 = new JMenuItem("Season 8");
menuDrivers.add(menuItemSeason8);
JMenuItem menuItemSeason9 = new JMenuItem("Season 9");
menuDrivers.add(menuItemSeason9);
JMenuItem menuItemSeason10 = new JMenuItem("Season 10");
menuDrivers.add(menuItemSeason10);
JMenu menuConstructors = new JMenu("Constructors Standings");
menuBar.add(menuConstructors);
JMenuItem menuItemSeason1Con = new JMenuItem("Season1");
menuConstructors.add(menuItemSeason1Con);
JMenuItem menuItemSeason2Con = new JMenuItem("Season 2");
menuConstructors.add(menuItemSeason2Con);
JMenuItem menuItemSeason3Con = new JMenuItem("Season 3");
menuConstructors.add(menuItemSeason3Con);
JMenuItem menuItemSeason4Con = new JMenuItem("Season 4");
menuConstructors.add(menuItemSeason4Con);
JMenuItem menuItemSeason5Con = new JMenuItem("Season 5");
menuConstructors.add(menuItemSeason5Con);
JMenuItem menuItemSeason6Con = new JMenuItem("Season 6");
menuConstructors.add(menuItemSeason6Con);
JMenuItem menuItemSeason7Con = new JMenuItem("Season 7");
menuConstructors.add(menuItemSeason7Con);
JMenuItem menuItemSeason8Con = new JMenuItem("Season 8");
menuConstructors.add(menuItemSeason8Con);
JMenuItem menuItemSeason9Con = new JMenuItem("Season 9");
menuConstructors.add(menuItemSeason9Con);
JMenuItem menuItemSeason10Con = new JMenuItem("Season 10");
menuConstructors.add(menuItemSeason10Con);
JButton btnRacingRecord = new JButton("Racing Record");
menuBar.add(btnRacingRecord);
JButton btnStats = new JButton("Stats");
menuBar.add(btnStats);
JButton btnRaceInput = new JButton("Race Input");
menuBar.add(btnRaceInput);
}
@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus,
int row, int column) {
// TODO Auto-generated method stub
return null;
}
class MyRenderer extends DefaultTableCellRenderer {
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus,
int row, int column) {
Component c = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
System.out.println(table.getValueAt(row, column));
if ("1".equals(String.valueOf(table.getValueAt(row, column)))) {
System.out.println("hi");
c.setBackground(Color.YELLOW);
} else {
c.setBackground(Color.RED);
}
return c;
}
}
}