|
-
January 30th, 2003, 08:55 PM
#1
changing the color of a row in a JTable
how do i change the color of a row in a JTable..Wat's the source code to use?... Anybody knows....?
Thanks alot...
-
January 31st, 2003, 07:32 AM
#2
This is asked quite often here. If you do a search of this forum for something like "JTable row color change", you should find plenty of information.
Time wounds all heels
Please use [CODE]...your code here...[/CODE] tags when posting code. If you get an error, please post the full error message and stack trace, if present.
-
February 3rd, 2003, 08:38 PM
#3
hi..i did a search of the forum..i found many similar queries regarding the changing of colors of rows in a JTable but i still do not understand..I know i have to use the TableCellRenderer but i'm not so familiar...Could u help me out again? Thanks alot..
-
February 4th, 2003, 07:07 AM
#4
OK, here's an example off the top of my head:
Code:
// Create a renderer to color a row
class MyTableCellRenderer extends DefaultTableCellRenderer {
public Component getTableCellRendererComponent(JTable table,
Object value,
boolean isSelected,
boolean hasFocus,
int row,
int column) {
// let the superclass do all the work
Component renderer = super.getTableCellRendererComponent(
value, isSelected, hasFocus, row, column);
// Change background to the required color
// if this is the required row
if (row == requiredRow) {
renderer.setBackground(requiredColor);
}
return renderer;
}
...
// Set this renderer for all class types (i.e. columns) in the table
myTable.setDefaultRenderer( Object.class, new MyTableCellRenderer());
This is untested code, but it shows the basic technique.
The higher, the fewer...
Please use [CODE]...your code here...[/CODE] tags when posting code. If you get an error, please post the full error message and stack trace, if present.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|