I am writing a prg which take a value from user and check weather its present in table or not....

table.getValueAt(i,j).toString().toLowerCase() == searchfield.getText().toLowerCase();

Well if yes then make that cell red...

What to write to make cell red?

I just posted an example of this over in a similar thread about JTable here. Perhaps it will help.

THANX , EZZARAL , but how to select a cell from coding.. what u posted only related to highlighting.

I HAVE DONE IT.... BUT ONLY A SINGLE CELL, I WANT TO SELECT ALL CELL WHICH HAS DATA...

table.getSelectionModel().setSelectionInterval(i,i);				table.getColumnModel().getSelectionModel().setSelectionInterval(j,j);

Then you will need to loop the cells and find it before you can select it.

YES I DID IT

for(int i=0;i<table.getRowCount();i++)
					for(int j=0;j<table.getColumnCount();j++)
						if(table.getValueAt(i,j).toString().toLowerCase().equals(searchfield.getText().toLowerCase()))
						{
							
							table.getSelectionModel().setSelectionInterval(i,i);
							table.getColumnModel().getSelectionModel().setSelectionInterval(j,j);
						}

BUT IT ONLY SELECT A SINGLE CELL, NOT ALL MATCHING CELL

You can add various selection intervals through the methods on ListSelectionModel, but setting multiple, non-contiguous single cells is tricky and not really that useful.

You are better off highlighting them and perhaps selecting the first.

Found solution..... and it worked great.

table.changeSelection(i,j,true,false);

u must give me a reputation point on finding such a solution for this forum :) Joking, and thanx for helping.

Nice work. I never noticed that method before - never had to select a bunch of single cells either though.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.