I am developing a java application that uses a jtabe to allow the user to capture data. This data would be written to a text file later. The application is working fine. Good. However, I wanted to add a button such that when a user click this button, the application should first ask the user to save(writing to a text file) and after this the application should close the table(terminating the the table instance from the memory) -more of closing a Word Document. My table is sitting on panel.

How do I perform this? I need the closing (a sort of myTable.close() - to errase data in the table) part only,everything is working fine.

2 Years
Discussion Span
Last Post by JamesCherrill

Do you just want to close a JTable inside a window that stays open, or do you want to close/free a whole winodw, including the JTable that's in it?


Hie James,

I would want to close both the table and the container.Look, the tbale is on a JPanel that is forming a JTabbedPane; the later is on a JFrame.

Like this: JFrame...>JTabbedPane...>JPanel...>JTable.

I would want to close both the JPanel and the JTable. The panel, that I want to close, is forming a Tab on a JTabbedPane.

Edited by Nation: clarifying


Simply call dispose() on the containing window (closes it and releases all its resources) and make sure you have no other references to the JTable so the garbage collecter can get rid of it.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.