This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Problem Displaying Text File in JTable  RSS feed

 
Jeff Zak
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've been looking at many examples all over the web on this the past several days but I'm just
stump'a'rood on this process. I have an Import button on my GUI which will search into the user.home
directory by default, which is where I have my text file stored. I can get into there no problem but nothing
seems to happen when I load my text file.

My button works fine up to line 8 of the code. I can get to my documents directory and select my file but nothing
else happens. No errors in the compiler after I click the button. What seems to be missing here ?




 
Peter Muster
Ranch Hand
Posts: 74
5
Eclipse IDE Python Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My guess is that you have to notify the GUI to redraw the table after your changes to the model content. Try to insert the following code at the end of your method.
 
Campbell Ritchie
Marshal
Posts: 55751
163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Avoid the close() calls by using try with resources (Java7+ only).
In Java8 you would reduce the change listener call to something like this:-
SwingUtilities.invokeLater(() -> fireTableDataChanged());
 
Jeff Zak
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Guys, my code was fine. My GUI only displays the first 5 of 35 lines and I never scrolled to the bottom. The code does write to the Jtable, not the way
I want it to, but, it DOES write. Again, I'm sorry about that and will start another thread on my issue.

 
Fred Kleinschmidt
Bartender
Posts: 560
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is the size of your table? How many rows are visible? Is the table in a scrolled window? Is there enough room for your table to display all 35 lines at the same time? Are you sure you are reading all 35 lines (write out the lines to the console when you add them to the table).
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!