Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 04-11-2009, 03:16 AM
Member
 
Join Date: Mar 2009
Posts: 2
Rep Power: 0
grottman is on a distinguished road
Default Display and Edit JTable after Deserialization
I'm using a Jtable as an "excel like" sheet for work use to build a schedule for my fellow employees. I'm serializing the model (defaulttablemodel) and need to have the ability to open, display and edit it (numerous times). I think(?) it's opening (being read) but I can't display it. Here's partial code listing (thanks in hopeful advance):

private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {
File currentDirectory = new File(".");
JFileChooser jFileChooser = new JFileChooser(currentDirectory);
jFileChooser.setFileFilter(new txtFileFilter());
jFileChooser.setFileFilter(new datFileFilter());

if(jFileChooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
try {
// Deserialize from a file
File file = new File("butttestTable.dat");
ObjectInputStream in = new ObjectInputStream(new FileInputStream(file));
// Deserialize the object
//javax.swing.JButton button = (javax.swing.JButton) in.readObject();
DefaultTableModel readModel= (DefaultTableModel)in.readObject();
JTable jTableRead = new JTable(readModel);

jTableRead.setColumnSelectionAllowed(true);
jTableRead.getTableHeader().setReorderingAllowed(f alse);
JScrollPane jScrollPaneRead = new JScrollPane();
jScrollPaneRead.setViewportView(jTableRead);

in.close();

}
catch (ClassNotFoundException e) {
e.printStackTrace();
}
catch (IOException e) {
e.printStackTrace();
}
//code to handle choosed file here.
}
}
Bookmark Post in Technorati
Reply With Quote
  #2 (permalink)  
Old 04-11-2009, 06:17 AM
Senior Member
 
Join Date: Jan 2009
Posts: 360
Rep Power: 2
toadaly is on a distinguished road
Default
You've created a JTable with your model, and you've added it to a JScrollPane, but you haven't added the JScrollPane to a contentpane of any panel.

You could created a JFrame, and then add the JScrollPane to it's contentpane...

Code:
JFrame frame = new JFrame();
frame.getContentPane().add(jScrollPaneRead );
frame.pack();
frame.setVisible(true);
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 04-11-2009, 05:26 PM
Member
 
Join Date: Mar 2009
Posts: 2
Rep Power: 0
grottman is on a distinguished road
Default
Hello and thanks for the advice. I tried your suggestion and got a blank frame. A gentleman from 'coderanch.com' suggested the following:

"I'm not sure I understand what you are trying to do there. You are creating some new Swing components and filling them with the contents of the table model you just read in, but you don't ever display those components. I think that would be why you don't see the data.

Why don't you just put the table model into an existing JTable which is already displayed? "

I gave that a try and received an error message to the effect that I was trying to load a JTable with a null model.

So, I checked the code that was serializing the table model and realized that I was remiss in not taking advantage of the try/catch. Which yielded the following error message:

Exception during serialization: java.io.NotSerializableException: java.lang.reflect.Constructor

So it appears that I have something in my JTable/model that is not serializable.

Thanks again for you help; now it's time for more head scratchin'.
Bookmark Post in Technorati
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Cant display data in jTable tpyq NetBeans 2 12-09-2008 03:42 PM
JButton to display JTable Nemesis777 New To Java 0 12-08-2008 01:16 PM
Display XML in JTable boy22 XML 2 12-07-2008 07:03 PM
Problems getting JTable to display information Gatts79 AWT / Swing 2 11-08-2008 03:35 AM
display rows in jtable osval AWT / Swing 1 08-06-2007 09:54 PM


All times are GMT +2. The time now is 01:20 PM.



VBulletin, Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2009, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org