File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Swing / AWT / SWT and the fly likes empty JTable Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "empty JTable" Watch "empty JTable" New topic

empty JTable


Joined: Mar 05, 2004
Posts: 5
I have a JTable whose values gets filled only dynamically.
At times, when the table is empty, I want to show a message like
"no records found" just under the table header.
Just like how in windows machine, when you make a search and if it doesnt
return any records, it prints "Search is complete. There are no results to display"
(stretching many columns) under the table header. I considered using JLabel
(as shown below) but there is always some space b/w the two components.
Let me know ur suggestions. Until then, lemme try out other Layout managers.
Just a code snippet:

(N. Pruett - fixed page-widening code.)
[ March 08, 2004: Message edited by: Nathan Pruett ]
Nam Ha Minh
Ranch Hand

Joined: Oct 31, 2011
Posts: 502

First, I suggest you to use a TableModel (e.g. AbstractTableModel) to separate data from the GUI.

PM Me If You Want to get Urgent Help on Java Programming
Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Posts: 2454
You can temporarily add the label to the table:

Then when you start adding data to the table you would need to remove the label from the table.
I agree. Here's the link:
subject: empty JTable
It's not a secret anymore!