Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 9 of 9

Thread: DefaultTableModel Serialization

  1. #1
    Forum Squatter newbie's Avatar
    Join Date
    Nov 2010
    Location
    North Wales
    Posts
    661
    My Mood
    Stressed
    Thanks
    28
    Thanked 115 Times in 106 Posts
    Blog Entries
    1

    Default DefaultTableModel Serialization

    Hey there, I'm attempting to store a JTable's TableModel by Serializing a DefaultTableModel object.

    The API says that DefaultTableModel implements the Serialization interface, but when I try and run my program
    I get the following exception.

    java.io.NotSerializableException: javax.swing.JTable$CellEditorRemover.

    Anyone get any ideas?

    	public void storeTableModel(DefaultTableModel model) {
    		ObjectOutputStream oos = null;
    		try {
    			oos = new ObjectOutputStream(new FileOutputStream(FILENAME));
    			oos.writeObject(model);
    		} catch (Exception e) {
    			e.printStackTrace();
    		} 
     
    		try {
    			oos.close();
    		} catch (IOException e) {
    		}
     
    	}
    Please use [highlight=Java]//code goes here...[/highlight] tags when posting your code


  2. #2
    Grand Poobah
    Join Date
    Mar 2011
    Posts
    1,549
    My Mood
    Grumpy
    Thanks
    0
    Thanked 169 Times in 160 Posts

    Default Re: DefaultTableModel Serialization

    The CellEditorRemover class does not implement Serializable.
    Improving the world one idiot at a time!

  3. #3
    Forum Squatter newbie's Avatar
    Join Date
    Nov 2010
    Location
    North Wales
    Posts
    661
    My Mood
    Stressed
    Thanks
    28
    Thanked 115 Times in 106 Posts
    Blog Entries
    1

    Default Re: DefaultTableModel Serialization

    I'm afraid I'm not with you.
    How would I tell it not to serialize that? I'm attempting to serialize a DefaultTableModel object which said it was serializable, so that's left me scratching my head.
    Please use [highlight=Java]//code goes here...[/highlight] tags when posting your code

  4. #4
    Grand Poobah
    Join Date
    Mar 2011
    Posts
    1,549
    My Mood
    Grumpy
    Thanks
    0
    Thanked 169 Times in 160 Posts

    Default Re: DefaultTableModel Serialization

    Where does the CellEditorRemover class come from?

    When you attempt to Serialize an object it also Serializes all the sub-Objects as well. Therefore all the sub-Objects must implement Serializable as well. From the error message you posted it suggests that there is at least one CellEditorRemover object somewhere in your Table or TableModel and that class does not implement Serializable.
    Improving the world one idiot at a time!

  5. #5
    Forum Squatter newbie's Avatar
    Join Date
    Nov 2010
    Location
    North Wales
    Posts
    661
    My Mood
    Stressed
    Thanks
    28
    Thanked 115 Times in 106 Posts
    Blog Entries
    1

    Default Re: DefaultTableModel Serialization

    From the limited resources found via Google, I've gathered that CellEditorRemover belongs to JTable more than TableModel, I've never manually registered a CellEditorRemover object with any of them, and I've looked for methods which might be able to detach/disable CellEditorRemover but to no avail. So I'm still dumbfounded as to what it essentially means. Why would a class be serializable when its enclosed class isn't?
    Last edited by newbie; August 15th, 2011 at 06:55 PM.
    Please use [highlight=Java]//code goes here...[/highlight] tags when posting your code

  6. #6
    Grand Poobah
    Join Date
    Mar 2011
    Posts
    1,549
    My Mood
    Grumpy
    Thanks
    0
    Thanked 169 Times in 160 Posts

    Default Re: DefaultTableModel Serialization

    The JTable that you are using is it a custom class? The CellEditorRemover class is not a nested class of the JTable class in the standard API. It would seem you are using a JTable class from a third party.
    Improving the world one idiot at a time!

  7. #7
    Forum Squatter newbie's Avatar
    Join Date
    Nov 2010
    Location
    North Wales
    Posts
    661
    My Mood
    Stressed
    Thanks
    28
    Thanked 115 Times in 106 Posts
    Blog Entries
    1

    Default Re: DefaultTableModel Serialization

    Not at all.
    I'm simply using the default JTable class, not sub-classing it or anything alike.
    Please use [highlight=Java]//code goes here...[/highlight] tags when posting your code

  8. #8
    Grand Poobah
    Join Date
    Mar 2011
    Posts
    1,549
    My Mood
    Grumpy
    Thanks
    0
    Thanked 169 Times in 160 Posts

    Default Re: DefaultTableModel Serialization

    JTable (Java Platform SE 6)
    The above link is to the JTable in the Java API and it only has 3 nested classes, none of them are CellEditorRemover.

    JTable
    The above link is to another JTable in what must be a different API. It has 12 nested classes and one of them is CellEditorRemover.

    I'm at a loss.
    Improving the world one idiot at a time!

  9. #9
    Forum Squatter newbie's Avatar
    Join Date
    Nov 2010
    Location
    North Wales
    Posts
    661
    My Mood
    Stressed
    Thanks
    28
    Thanked 115 Times in 106 Posts
    Blog Entries
    1

    Default Re: DefaultTableModel Serialization

    Yeah me too

    public JTable getSemester1JTable() {
    		final JTable TABLE = new JTable();
    		TABLE.setModel(MODEL);
     
    		MODEL.setColumnIdentifiers(getColumnHeader());
     
    		DefaultTableCellRenderer rightRenderer = new DefaultTableCellRenderer();
    		rightRenderer.setHorizontalAlignment(JLabel.CENTER);
     
    		TableColumn column = null;
    		for (int i = 0; i < 10; i++) {
    			column = TABLE.getColumnModel().getColumn(i);
    			column.setResizable(false);
    			column.setCellRenderer(rightRenderer);
    		}
     
    		TABLE.getTableHeader().setForeground(Color.BLUE);
    		TABLE.setShowVerticalLines(true);
    		TABLE.setSelectionBackground(Color.PINK);
    		TABLE.setSelectionForeground(Color.GREEN);
    		TABLE.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    		TABLE.setPreferredScrollableViewportSize(new Dimension(1500, 400));
    		TABLE.setFillsViewportHeight(true);
    		TABLE.setRowHeight(80);
    		TABLE.setRowSelectionAllowed(false);
     
    		return TABLE;
     
    	}

    Thats the code I use, and In another class I simply have: JTable table = myObject.getSemester1JTable();
    Please use [highlight=Java]//code goes here...[/highlight] tags when posting your code

Similar Threads

  1. Sub class Serialization
    By Param in forum Java Theory & Questions
    Replies: 6
    Last Post: April 23rd, 2010, 02:04 AM
  2. Writing data to the java DefaultTableModel
    By dubois.ford in forum What's Wrong With My Code?
    Replies: 1
    Last Post: April 1st, 2010, 08:43 PM
  3. Exception and Serialization Problems
    By chrisych in forum Exceptions
    Replies: 0
    Last Post: February 7th, 2010, 10:30 AM
  4. serialization problem
    By Park in forum Object Oriented Programming
    Replies: 2
    Last Post: November 26th, 2009, 03:44 PM