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?

Recommended Answers

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

Jump to Post

Ah, yes, selection is different. You can use the methods on JTable to select both the row and column setRowSelectionInterval(int index0, int index1) and

Jump to Post

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

Jump to Post

All 10 Replies

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 1.21 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.