• Post Reply Bookmark Topic Watch Topic
  • New Topic

PASSING DATA IN A JTable  RSS feed

 
Kieran Murray
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I started off this topic in two forums - yours and Sun forum.

View Topic @ http://www.coderanch.com/t/410463/java/java/Problems-passing-data-file-JTable

This caused some frustration and I then said that the Sun team should look at the question as I asked them first.

I think they gave up on me.

Your moderator suggested that I pass this topic to the intermediate team and I am doing so now. I will inform Sun that the topic on their site is moribund.

The problem is getting data out of an object. I have a JFrame and in that a JTabbedPane. In the JTabbedPane is a JTable. I pass the information from the JTable into the BusbarRecords class. I can not then access the information in this class when I come to save the file. How do I do this. When I instantiate the file in the main PowerFrame class the problem is I think that it instantiates a new object.

I include the code below for ease of reading. This is part of my MSC and I am getting desperate.

Main class PowerFrame



BusbarsUI class



BusbarRecords class



JavaFilter class

 
Campbell Ritchie
Sheriff
Posts: 53774
128
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry, I saw this last night and it was too late to reply.

I am afraid the app is too large just to read through and understand, so you will have to follow the execution with a debugger.

I suggest you get yourself a decent IDE, eg Eclipse, NetBeans, IntelliJ, and use the debugger.

Double-click the left side of the editor pane, where the line numbers go, and a blob will appear. This represents a breakpoint. Run the app from the IDE with run->debug, and when you get to the breakpoint it stops. You can open a "debug perspective" which allows you to see the objects and all their values throughout the whole app. I had to do the same with a much bigger MSc thing this time last year, and it isn't difficult once you get the hang of it.

Once you stop at the breakpoint, you have 3 options to go forward, which I think can be selected with the f5 f6 and f7 keys.
  • Step Into: follows the normal flow into method calls etc.
  • Step Over: Follows the flow but misses out details of method calls.
  • Step return: Goes to the end of the present method and back to where it was called from.
  • Careful with "step return;" it can go back too far and terminte the app if you aren't careful. I think they are called Step because they go one step at a time.

    Don't know where to put the breakpoint, maybe in the actionPerformed method of the Listener on your save item.

    Good luck with it, and we shall try to be more helpful than on the other site
     
    Campbell Ritchie
    Sheriff
    Posts: 53774
    128
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Several weird things:
  • You are using .java as a filter, and creating a .dat file.
  • You are creating a new BusbarRecords object.
  • Your BusbarRecords constructor does not set up the initial state of an object. I think, maybe, you can't set up BusbarRecords correctly with a BusbarRecords(String) constructor at all.
  • Your saveFile() method which returns "true" from CANCEL_OPTION is odd. You would usually only use if (chooser.showSaveDialog(...) == JFileChooser.APPROVE_OPTION){...}
  • In your saveFile method, you are choosing a file, then setting the file to a different file.
  • After that, there doesn't seem to be any code which actually writes anything to the file.
  • You are using Vector rather than a more modern class, although that might be required by the constructor of one of the Components.
  • You are using Vector plain (raw) rather than Vector<BusbarSomethingOrOther>
  • You might also lose marks for inconsistent indenting conventions and capitalisation (it should be busbar rather than Busbar for the name of the object), and incorrect formatting for your comments.
    Also if I were marking I would look askance as 1-indexed "for" loops. You should start with int i = 0;

    Have you had any luck with the debugging?

    Sorry I have got so many complaints, but it isn't my application and I am not quite sure what it is supposed to do. You would have made it easier for us (and probably picked up a few more marks) by adding more comments, particularly documentation comments.
     
    Rob Spoor
    Sheriff
    Posts: 20895
    81
    Chrome Eclipse IDE Java Windows
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Moving to AWT / Swing
     
    Kieran Murray
    Ranch Hand
    Posts: 47
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Bob and Campbell,

    Thank you for your time. The solution - and I found this by accident and I am not quite sure why is works is to make the String variable value in BusbarRecords static. Then it holds it value.

    I can now get data into an array, save the array in a file and read back from the file.

    My problem now is that the JTable will not update with the new data.

    I will get back to you if I can not solve it.

    Thanks again for your help.
    In the immortal words of Buzz Lightyear "To infinity and beyond".
     
    Campbell Ritchie
    Sheriff
    Posts: 53774
    128
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Very surprised at that.

    Another weird thing I have found is your getValue() method which appears to act as a set method.
     
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!