0

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?

3
Contributors
10
Replies
11
Views
6 Years
Discussion Span
Last Post by mKorbel
Featured Replies
  • 1
    Ezzaral 2,714   6 Years Ago

    I just posted an example of this over in a similar thread about JTable [URL="http://www.daniweb.com/software-development/java/threads/373078/1605358#post1605358"]here[/URL]. Perhaps it will help. Read More

  • 1
    Ezzaral 2,714   6 Years Ago

    Ah, yes, selection is different. You can use the methods on JTable to select both the row and column [URL="http://download.oracle.com/javase/7/docs/api/javax/swing/JTable.html#setRowSelectionInterval(int,%20int)"]setRowSelectionInterval(int index0, int index1)[/URL] and [URL="http://download.oracle.com/javase/7/docs/api/javax/swing/JTable.html#setColumnSelectionInterval(int,%20int)"]setColumnSelectionInterval(int index0, int index1)[/URL]. You'll still need the highlight renderer if you want to make a cell red. Read More

  • 2
    Ezzaral 2,714   6 Years Ago

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

  • Found solution..... and it worked great. [code] table.changeSelection(i,j,true,false); [/code] u must give me a reputation point on finding such a solution for this forum :) Joking, and thanx for helping. Read More

0

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

0

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);
0

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

0

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.

Edited by Ezzaral: n/a

1

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.

0

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

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.