This week's book giveaway is in the Agile and Other Processes forum.
We're giving away four copies of The Journey To Enterprise Agility and have Daryl Kulak & Hong Li on-line!
See this thread for details.
Win a copy of The Journey To Enterprise Agility this week in the Agile and Other Processes forum! And see the welcome thread for 20% off.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

Refreshing a window  RSS feed

 
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I have a JFrame that contains 3 JPanels. One of the panels contains a JScrollPane which contains a JTable.
How can I refresh the screen after I have added to the table?

Thank you.
 
Sheriff
Posts: 23640
48
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Normally if you update the JTable via its table model, that happens automatically. Perhaps you aren't doing it that way? Or perhaps you wrote your own table model which doesn't notify the JTable of changes?
 
Geoff Jefferson
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
>> Normally if you update the JTable via its table model, that happens automatically. Perhaps you aren't doing it that way? Or >> perhaps you wrote your own table model which doesn't notify the JTable of changes?

I do have my own table model, and I tried calling a method that implements the fireTableDataChanged() method, but that didn't do any good. I have employe a ListSelectionListener to getValueAt(), I suppose I could try setValueAt().

G.
 
Geoff Jefferson
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
>> I have employe a ListSelectionListener to getValueAt(), I suppose I could try setValueAt().

...eh' probably not. Don't know what I was thinking.
I don't understand why fireTableDataChanged() didn't work.

 
Geoff Jefferson
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
... hey are Katydid's edible? One just landed on my lamp.

 
Bartender
Posts: 1561
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Geoff Jefferson wrote:>> I have employe a ListSelectionListener to getValueAt(), I suppose I could try setValueAt().

...eh' probably not. Don't know what I was thinking.
I don't understand why fireTableDataChanged() didn't work.


Hard to say without code. If you can distill your problem into an SSCCE, that would help our figuring this out immensely.


... hey are Katydid's edible? One just landed on my lamp.


Why not give it a try and find out!

Luck!
 
Rancher
Posts: 2932
19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I do have my own table model,



Why? Whats wrong with the DefaultTableModel?

and I tried calling a method that implements the fireTableDataChanged()



You don't need to implement this method its already implemented in the AbstractTableModel.

If you think you really need to create a custom model then look at the source code of the DefaultTableModel to see how it uses the fireXXX methods.
 
Geoff Jefferson
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Here is my example. There are two files. I hope that is okay.
I'm trying to get the screen to refresh after entering data into textFields upon button click.







 
Rob Camick
Rancher
Posts: 2932
19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You where asked for a SSCCE.

Your question is about refreshing a JTable. Whats with all the other code?
 
Geoff Jefferson
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Geoff Jefferson
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Previousely I was loading the table from a file. Here I am trying to load the table on the fly by clicking on the button
which should load the list.

 
pete stein
Bartender
Posts: 1561
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One problem is here:




If you create a new non-displayed "Table" object in this method and add something to it, what effect will this have on the completely
separate and distinct Table object (in other words "this") that is being displayed?

Edit: problem number 2: you are tring to fiddle directly with the List that is at the core of the table's model, a field that should be
private, rather than using a public addRow method or something similar that fires the table model's listeners.

problem number 3 (to echo rob camick): why use AbstractTableModel when a DefaultTableModel would be a much better fit and
would be much easier to use.

.....

possibly more to come...
 
Geoff Jefferson
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you create a new non-displayed "Table" object in this method and add something to it, what effect will this have on the completely
separate and distinct Table object (in other words "this") that is being displayed?

I see.

Edit: problem number 2: you are tring to fiddle directly with the List that is at the core of the table's model, a field that should be
private, rather than using a public addRow method or something similar that fires the table model's listeners.

So I shouldn't try to add to the list at all?

problem number 3 (to echo rob camick): why use AbstractTableModel when a DefaultTableModel would be a much better fit and
would be much easier to use.

My goal is to be able to use the list as an item file that can be edited. Wouldn't I need an Abstract model to do this?


 
pete stein
Bartender
Posts: 1561
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Geoff Jefferson wrote:

pete stein wrote:
Edit: problem number 2: you are tring to fiddle directly with the List that is at the core of the table's model, a field that should be
private, rather than using a public addRow method or something similar that fires the table model's listeners.



So I shouldn't try to add to the list at all?


Nope, that would be breaking encapsulation. Again, if you are using an AbstractTableModel, you want to give the model a public addRow(....) method that accepts an array of objects, or an object of your data class, and then have the data added to the model's core, to it's private List from within this method. You can then fire the listeners which I don't see you ever doing.

problem number 3 (to echo rob camick): why use AbstractTableModel when a DefaultTableModel would be a much better fit and
would be much easier to use.


My goal is to be able to use the list as an item file that can be edited. Wouldn't I need an Abstract model to do this?


Nope, it would be much easier to use the default model, even for this. Now when you say you want to edit this file, do you mean that it should be in text format and editable via a text editor? If so, then serialization won't work at all.

The DefaultTableModel class has an addRow method that fires listeners for you. It also has getDataVector if you want the Vector of Vectors that holds the data, but you may be better of just calling getValueAt(...) to extract your data from the model.
 
pete stein
Bartender
Posts: 1561
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The only disadvantage I see of using a DefaultTableModel is that you would have to "un-box" your ItemFile objects into an array of String to be able to add them into a row, and likewise you'd have to "box" the array of String into an ItemFile object to extract the data and use it as an ItemFile datum, but this problem is minor compared to the effort saved by using the pre-made DefaultTableModel.

e.g.,
 
Rob Camick
Rancher
Posts: 2932
19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1) 300+ lines of code is NOT a SSCCE.
2) Still using a custom model

I'm amazed someone took the time to glance through all that code to provide help. Too bad you can't make the effort.

Apparently I'm wasting my time since none of my suggestions have been followed. Good luck with future posting I won't contine to waste my time.
 
Geoff Jefferson
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
>> Now when you say you want to edit this file, do you mean that it should be in text format and editable via a text editor? If >> so, then serialization won't work at all.

My intention was to store each item as an ItemFile object in an ArrayList, and then to store the ArrayList on file.
The editing would be done by changing what is in the table, adding, or deleting also from the table. Then to put
back into the list and then to file.

>> The DefaultTableModel class has an addRow method that fires listeners for you. It also has getDataVector if you want the >> Vector of Vectors that holds the data, but you may be better of just calling getValueAt(...) to extract your data from the
>> model.

So I need to figure out a way to copy my list into Vector for use in the model, and then from Vector to list for persistant
storage?




 
Geoff Jefferson
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
300+ lines of code is NOT a SSCCE. Even after you where asked a 2nd time by two different people to post a SSCCE.

I'm amazed someone took the time to glance through all that code to provide help. Too bad you can't make the effort.

You actually learn more by creating the SSCCE.


I'm sorry. I'll not let it happen again. I just wanted to represent exactly what I was trying to do.

 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!