tags:

views:

51

answers:

3

i have a JTable with row filter.

once fitered if i didn't get any row then i have to show a string like "Nothing found to display " inside table as first row.

please do needful.

Thanks , Narasimha

A: 

If the filter has excluded all rows, the result returned by getViewRowCount() will be zero. You can update the GUI accordingly; setToolTipText() is handy if screen space is lacking.

Here's an example:

TableModel model = ...
JTable table = new JTable(model);
TableRowSorter<TableModel> sorter = new TableRowSorter<TableModel>(model);
table.setRowSorter(sorter);
JScrollPane pane = new JScrollPane(table);
JLabel label = new JLabel("");
...
String s = "Rows: " + sorter.getViewRowCount()
pane.setToolTipText(s);
label.setText(s);
trashgod
A: 

Can u provide sample code?

it's very urgent

Narasimha
@Narasimha Rao, @Narasimha: This should be a comment to an existing answer.
trashgod
A: 

To show a line of text in the multicolumn table can be quite difficult, the span AFAIK is not supported. One possibility would be to hide all data columns (to show them later you have to memorize them somewhere) and show one column for the message.

An easier way would be to create a JPanel with CardLayout, add 2 cards - one containing table and one containing your empty data warning. If the filter returns empty result, show the card with empty warning, in other case - show the table.

Taisin