aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Using AbstractTableModel to show data from user defined Classes - problem passing/defining the data Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Using AbstractTableModel to show data from user defined Classes - problem passing/defining the data" Watch "Using AbstractTableModel to show data from user defined Classes - problem passing/defining the data" New topic
Author

Using AbstractTableModel to show data from user defined Classes - problem passing/defining the data

Matt Collis
Greenhorn

Joined: Jun 21, 2012
Posts: 5
Hi all, I have a problem when passing a user defined class to an extended AbstractTableModel

I will ask up front for some patience as I am new to Java having done most of my (bad) coding in .NET

Scenario: I have a form with a jTree, I make several calls to a database and I populate the jTree (lazily) with the returned objects, I pass these objects to different Classes (defined by me) to store the relevant information. When the use selects a Node in the jTree I would like to retrieve the user object and display its details in a jTable (in .NET I used the ListView and jTable seems to be the best thing in Java)

I coded a new AbstractTableModel inside the main class and call it when the user selects a node, this code works fine and I can set column names and return tree node data, however this is within the main class.....so.....

After doing some reading and looking at some examples I decided to create my own AbstractTableModel class for each of my own classes and then instantiate them on demand by passing the selected tree node to the relevant table model (sounds reasonable??)

The problem is that for some reason my class object is not being passed correctly and I get a null exception, I have debugged and can see that the object I pass is the correct one but it never gets used in my table model

My table model class is here:




I can't figure out where it goes wrong? I think my constructor is correct and I know I pass the correct user object from the tree

Here is the code that works from inside the main class:


Can someone point me in the right direction? I have been searching and searching and I think I am doing things in the correct order but i'm stuck as to where I have gone wrong......apologies if this may have been answered somewhere on the forum - I did use the search button first, honest!!

https://forums.oracle.com/forums/thread.jspa?threadID=2405115&tstart=0

The question is also posted on the Oracle forums at the above link, so this is a cross-post folks........
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
code better formatted here

https://forums.oracle.com/forums/thread.jspa?threadID=2405115&tstart=0

I think I know the problem, but not gunna (possibly) waste my time testing the solution
Matt Collis
Greenhorn

Joined: Jun 21, 2012
Posts: 5
Why Micheal - thanks very much for your useful insights on which websites have the best code tags built in, and also for not giving any hints as to where i'm going wrong

You're a star.......
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
> and also for not giving any hints as to where i'm going wrong

if two people post solutions on different websites, one of them has totally wasted his/her time.

if our time is unimportant to you, you getting my solution is equally unimportant to me.

> You're a star.......

we agree on something
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4638
    
    5

Matt Collis wrote:Why Micheal - thanks very much for your useful insights on which websites have the best code tags built in

The code tags don't automagically format your code for you. You posted unformatted code here, so don't try to shift the blame.


luck, db
There are no new questions, but there may be new answers.
Matt Collis
Greenhorn

Joined: Jun 21, 2012
Posts: 5
Darryl - not trying to shift any blame anywhere, it would appear copy/paste didn't go as I expected here, I should have checked the results more closely as I pasted the same code on both sites and the Oracle one seemed to paste formatted, this one didn't, user error is the most likely scenario

Many people post the same question on different forums - nothing unusual there, there are many ways to skin a cat and getting a few answers can point to different methods and ways of doing things, in my experience this is more helpful as some methods are far faster/better than others

"A friendly place for programming greenhorns"

I see the site owners have a strong sense of irony.....

If you don't want to help then just don't post a reply as it wastes both your time for posting and mine for reading the reply. I've only been developing in Java for 2 weeks, I know I've a lot to learn and help is appreciated. Sarcastic replies pointing out my errors do not really add anything useful to the debate

I will reformat the posted code as I admit it makes life easier, thanks for the pointer
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
> Many people post the same question on different forums - nothing unusual there,...

if done correctly, everyone benefits i.e. including a link to the other forum helps
those looking for a solution - the solution might not be on forumA, but a link to
forumB might have the solution, also, those who donate their time to help others
can easily see if the problem has already been answered, and can move on to help
others.

> If you don't want to help then just don't post a reply as it wastes both your time for posting...

I have no intention of helping, just happy to alert other regulars that they may be wasting their time.
I've seen too many (really) smart people depart these forums simply because of posters who
'want an answer now' and don't care about anyone else.

Matt Collis
Greenhorn

Joined: Jun 21, 2012
Posts: 5
Hi Michael,

"if done correctly, everyone benefits i.e. including a link to the other forum helps
those looking for a solution - the solution might not be on forumA, but a link to
forumB might have the solution, also, those who donate their time to help others
can easily see if the problem has already been answered, and can move on to help
others. "

I took your advice on board and edited my original post so the snippets are formatted. I also read some of the advice in FAQ bit about double posting and so also mentioned the fact I had posted the question on another forum; and provided the link to make it clear the same issue was on both forums - I'm sure you spotted it

If you could point me to the bit where "I want an answer now" and "Don't care about anyone else" I would appreciate it as I have re-read the post a few times and am struggling to find those parts??

If the question is answered on either site I would then put the link to the answer on both to avoid the scenario you point out - it is only fair to do so

Perhaps people depart these forums because of the superior "I'm not wasting my time with you" attitudes of other posters and the smarmy sarcastic replies to genuine questions?

I believe I have tried to put my issue across in a friendly enough way, having been informed of some practical and 'best practices' for posting I have edited the original to try and rectify the errors

I don't see why you have such a big problem here mate? It's pretty obvious you're not interested in helping out; fine with me, don't bother!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Using AbstractTableModel to show data from user defined Classes - problem passing/defining the data