Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Question about initial dispaly of table

 
Holmes Wong
Ranch Hand
Posts: 163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, rachers:
I have a TableModel to store the search results. My question is: how do we set up the initial display of the table? put entire database in table model and display it, then refresh the table based on search results? or display an empty table first?---if I set cells to null, I get nullpinterexception. Any suggestion is appreciated.
 
Sai Prasad
Ranch Hand
Posts: 560
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
set the table model with null Object[][] array in it. You should see a blank table.
 
Holmes Wong
Ranch Hand
Posts: 163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Sai:
I could display an empty table now. I still have trouble refresh the table. This is what I do not understand: if I display an empty table first like this:

Since the table is already added, once I get the search results, I have to do this again? :

I am confused here, the above code certainly will not work, should I use a TableModelListener to refresh table? Thanks.
 
christy smile
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, I have a similar doubt in mind while designing the GUI. Then, I decided that I will display an empty table when the client first comes up. I supplied a button in the GUI called "ShowAll" that displays everything in db.db in the JTable. Anyone think this is a good idea?
Thanks.
 
dean tomlinson
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi christy,
i personally think it is better to have just one button to execute the retrieval of the flights, based on the selections in your comboboxes / textfields.
i've got another button titled "reset" that sets my combo boxes to Any, so the user can easily retrieve all flights using 2 button clicks.
good luck with the assignment. dean
 
Holmes Wong
Ranch Hand
Posts: 163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Christy:
I think the idea about blank table or your idea
are both ok.
Guys:
I still cannot show the table for search results
after I set up an initial empty table. Should I define this blank table in my table model class then new a table model with null table values? Or define it in GUI without using table model first?
The latter seems not work. Any advice? Thanks.
Originally posted by christy smile:
Hi, I have a similar doubt in mind while designing the GUI. Then, I decided that I will display an empty table when the client first comes up. I supplied a button in the GUI called "ShowAll" that displays everything in db.db in the JTable. Anyone think this is a good idea?
Thanks.
 
christy smile
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, Dean,
I have a "reset" button as well, which clears the origination and destination fields and display the whole database in JTable. Now, it seems "ShowAll" button is a bit redundant. With your reset button, do you field the fields with "any" or leave them blank? Mine leave the fields blank. I started a different thread about handling the blank textfield for criteriaFind, please take a look and give me your thoughts about it.
http://www.coderanch.com/t/181321/java-developer-SCJD/certification/initial-dispaly-table
Thanks
 
Sai Prasad
Ranch Hand
Posts: 560
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
All you have to do is create only one instance of a JTable and only one instance of a TableModel. Table model can be either DefaultTableModel instance or you can extend AbstractTableModel and create your own model. In your table model, you provide methods to populate the two dimesional array or some collection in it.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic