在Jtable的一行中设置颜色 [英] Setting color in a row of a Jtable

查看:106
本文介绍了在Jtable的一行中设置颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要帮助.

我有两个桌子.

在指令表中,必须根据流水线阶段中正在执行的指令来突出显示每一行.举例来说,在时间t10,I5处于IS阶段,因此必须突出显示指令表中的I5或更改指令表中行的颜色.例如,I5行为红色,I6行为粉红色, I7是绿色,I8是灰色,I9是橙色.

In the instruction table., each row must be highlighted according to what instruction is being execute in the pipeline stages. Say for example., at time t10, I5 is in IS stage, so I5 in instruction table must be highlighted or the color of the row in instruction table must be change.say, I5 row is color red, I6 row is color pink, I7 is color green, I8 is color gray, I9 is color orange.

我真的需要您的专业知识.,谢谢..:)

I really need your expertise., thank you.. :)

推荐答案

请尝试使用自定义呈现方式尝试此操作,这样可以轻松解决您的问题

Please try this using custom rendered which will solve your problem easily

JTable myTable = new JTable();
// You can specify the columns you need to do the required action
myTable.getColumnModel().getColumn(0).setCellRenderer(new MyRenderer());

public class MyRenderer extends DefaultTableCellRenderer {

    // This is a overridden function which gets executed for each action to
    /// your Jtable
    public Component getTableCellRendererComponent (JTable table, 
        Object obj, boolean isSelected, boolean hasFocus, int row, int column) {

       // Use this row, column to change color for the row you need, e.g.
        if (isSelected) { // Cell selected
           cell.setBackground(Color.green);
        }
    }
} 

注意:此渲染器除了用于突出显示颜色外,还可以用于其他用途,请参考

Note: this renderer can be used for more than doing color highlighting, please refer custom Jtable rendering. For timing your changes in response to the queue, you can schedule it in a separate thread.

这篇关于在Jtable的一行中设置颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆