public class TableRow extends JFrame { public TableRow() { JTable table=new JTable(new DefaultTableModel(new Object[][]{ {"A","Delhi","111111"}, {"B","Agra","222222"}, {"C","Mumbai","333333"}, {"D","Chennai","444444"}, {"E","Baroda","555555"}, {"F","Kolkata","666666"}}, new Object[]{"Name","Address","Phone No"})); ChangeColor renderer=new ChangeColor("Name");
for (int i=0;i<table.getColumnCount();i++) table.getColumn(table.getColumnName(i)).setCellRenderer(renderer); JScrollPane scroll=new JScrollPane(table); this.setContentPane(scroll); this.setBounds(100,50,300,150); } public static void main (String arg[]) { TableRow tes = new TableRow(); tes.setVisible(true); tes.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } } class ChangeColor extends JLabel implements TableCellRenderer { private String columnName; public ChangeColor(String column) { this.columnName = column; setOpaque(true); } public Component getTableCellRendererComponent(JTable table, Object value,boolean selected, boolean hasFocus, int row, int column){ Object columnValue=table.getValueAt(row,table.getColumnModel().getColumnIndex(columnName)); if (value != null) setText(value.toString()); setBackground(table.getBackground()); setForeground(table.getForeground());
if (columnValue.equals("A")) setBackground(Color.green); if (columnValue.equals("B")) setBackground(Color.red); if (columnValue.equals("C")) setBackground(Color.blue); if (columnValue.equals("D")) setBackground(Color.pink); if (columnValue.equals("E")) setBackground(Color.orange); if (columnValue.equals("F")) setBackground(Color.yellow); return this; } }
Thanks
Related Pages:
how to mark different colors for diffent rows - Java Beginners how to markdifferentcolors for diffent rows Hi,
i have drawn a simple table using swings and now i want to markdiffentcolors for each row..............my target is to have each color for each row.......first row
how to mark different colors for diffent rows - Java Beginners how to markdifferentcolors for diffent rows Hi frends,
Actually yesterday i had a question that, how can i markcolors to my rows in the table... question is how can i solve this problems means my table should have colored rows
ShortBuffer in java, How to reset the mark of short buffer.
ShortBuffer in java, How to reset the mark of short buffer.
In this tutorial, we will see how to reset the mark of short buffer. ShortBuffer API...() method reset the mark at
previous position.
 
display of colors in a table - JSP-Servlet
display of colors in a table Hi,
If i have a table of 4 by 4 boxes, numbering from 1-16 in sequence, how do i make them display one column of one color and another column of another color?
Thanks! Hi Friend
How to show Rainbow Colors How to show Rainbow Colors
This section illustrates you how to show all the seven colors of colors.
The Rainbow consists of seven colors known as VIBGYOR i.e. violet
How to sort the rows in SQL? How to sort the rows in SQL? How to sort the rows in SQL?
Hi,
Here is the answer,
The ORDER BY clause allows you to sort the records in your result set. The ORDER BY clause can only be used in SELECT statements
How to insert rows in jTable? How to insert rows in jTable? Hi,
I need to take input from user using JTable. I want an empty row to appear after clicking a insert button... not figure out how to. I used DefaultTableModel but wasnt able to insert a row
JSlider with RGB Colors
JSlider with RGB Colors
In this section, you will learn how to create sliders to show RGB colors.
In this example, we have created three horizontal sliders, first one as
red, the second one as green and the third one as blue
updating rows which contains same id, different value for each row
updating rows which contains same id, different value for each row  ... 30
From the above table we can identify that 4 rows with sid 1 and 3 rows with sid 5. Like this table may contains multiple records with same sid
Comparison of corresponding rows in a DB
Comparison of corresponding rows in a DB How to compare corressponding rows in a database using Java????? ex...!!!
Thankin u
Grid rows delete issue
Grid rows delete issue I have a grid having rows with Remove button to remove rows,But we also havae an facility to remove those rows on onchange event of dropdown also,so if we delete middle row and then remove all rows
Reset( )and Mark( )
Reset( )and Mark( ) i am using buffer reader to read each line using... using mark() i have to specify the size. For a huge file, length has to be stored in long but mark only takes int type value..
any other function that i can
different borders
; enter the values in that cell then we create different borders and we
also sets the differentcolors. .
Code description
The package we need to import...
different borders
 
Php Sql num rows
Php Sql num rows
This example illustrates how to find number of rows... and
find the number of rows of the table by mysql_num_rows methods. The output...);
$num_rows = mysql_num_rows($result);
 
MySQL Affected Rows
MySQL Affected Rows
This example illustrates how to show the affected rows... rows affected (0.08 sec)
Here update a table "...;
Query OK, 0 rows affected (0.00 sec)
Rows matched: 1 Changed: 0
Php Sql Number of Rows
Php Sql Number of Rows
This example illustrates how to count the rows... of rows
of the table. To find the number of the rows we use the mysql_num_rows..._rows($res);
print("$number_of_rows rows 
Displaying Rows - JSP-Servlet
Displaying Rows Hi, I need your support on how to display data from ms sql 2000 database into an html form text box and text area, using java servlet or jsp Hi friend,
This is form code,
display data
JavaScript Hide Table Rows
;
In this section, you will learn how to hide table rows using JavaScript...
JavaScript Hide Table Rows... object grabs the id of the table. Then we have determined the length of
rows
return all rows mysql php
return all rows mysql php How to find or return results that are not available in another table .. using join method in PHP and MYSql.
SELECT * FROM Declined
LEFT JOIN Request ON Declined.RequestID
How to make a button of different behaviour? How to make a button of different behaviour? Suppose In a jsp page I have a button SAVE with id="btnSave" value="SAVE" and a javascript function... ajaxInsertUpdateData(document.getElementByID("btnSave1").value,......); How to do
JDBC: Rows Count Example
JDBC: Rows Count Example
In this section, You will learn how to count number of rows in a table using
JDBC API.
Counting number of rows -
To count the number of rows of a table we use COUNT(*). It will returns the
number of rows
PHP SQL Number of Rows
PHP SQL Number of Rows
This example illustrates how to count the rows of the table.
To understand how to count the number of rows in a table, we have created a sql_num_rows.php
Getting the Number of Rows and Columns in JTable
will learn how to get the number of
rows and columns in JTable.
This program simply helps us for getting the number of
rows and columns from the JTable by using...
Getting the Number of Rows and Columns in JTable 
Java get number of rows in resultset
Java get number of rows in resultset
In this section, you will learn how to retrieve the number of rows from the
database table. As you know that the data
how to Insert Array Values Into Separate Rows using java? how to Insert Array Values Into Separate Rows using java? how to Insert Array Values Into Separate Rows using java? class InsertArrayValuesInSeparateRow{
public static void main(String[] args
Adding checkbox in table using that delete table rows
for how to add checkbox in table,the table data from database.Using that checkbox select more than than one rows,and using delete button i want to delete the selected rows using swing in java
Php Sql num rows
Php Sql num rows
This tutorial illustrates how to find number of rows of the table...
to find the number of rows in the table. We created a connection from database
Inserting Rows in a JTable
in a
table. This tutorial helps you in how to insert rows in a JTable to specified...
Inserting Rows in a JTable
 ...
3 rows and 2 columns. If you want to insert a data at any location
insert rows from browsed file to sql database
insert rows from browsed file to sql database i need to insert rows from excel to database by browsing the file in jsp. by connecting both..., content of the file has to go to database. how can i insert record into database