gpt4 book ai didi

java - 在 JTable Java 中更改行背景

转载 作者:行者123 更新时间:2023-12-01 19:03:01 26 4
gpt4 key购买 nike

我的项目中有一个名为tasktable的表。它从数据库(oracle)检索数据。如何更改单元格 ex 中具有颜色的行的颜色。 (i,8) 当我点击刷新按钮时自动?

我已经尝试了很多次将该源代码放在特定行上,但最终给所有表格着色:

          int count;      
count = tasktable.getRowCount();
for (int i=0;i<count;i++)
{
rr = new Object ();
rr = tasktable.getModel().getValueAt(i,8);
if(rr.equals("GREEN"))
{
setBackground(Color.GREEN);
}
if(rr.equals("red"))
{
setBackground(Color.red);
}
if(rr.equals("BLUE"))
{
setBackground(Color.BLUE);
}
if(rr.equals("yellow"))
{
setBackground(Color.yellow);
}
if(rr.equals("pink"))
{
setBackground(Color.pink);
}
if(rr.equals(null))
{
setBackground(null);
}

如何帮助我解决这个问题?

最佳答案

添加自定义TableCellRenderer到您的餐 table 。

关于java - 在 JTable Java 中更改行背景,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11507913/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com