Hi, i have added a JTable to a JPanel which displays data from the data base. Now i have also added a button to the same panel. What i need is this table should be refreshed an displayed on the panel when i click that button but i am unable to achive this i added a action listener but i am getting many errors please some body help here is my code.
This code is working but i am unable to refresh and the table is displayed when i launch the application. Please Somebody help.
Difficult to read that code. Please tell us more precisely which errors you are getting, and also provide details of the ActionListener.
Joined: May 29, 2008
Hi, this is the complete code along with ActionListener. I i am facing two problems with this. First i am unable to get the column headings. Secondly when ever i am trying to add the JScrollPane i am getting error. With the JScrollPane the output is fine but i am unable to sroll. The code as well as error are given below
The code has compiled with zero errors but when i am trying to execute it is giving the following error. I have marked the errored line with >>>>and<<<<
I don't know about the others here, but I find it much easier debugging a small program that is compilable and runnable allowing me to see the error, called an SSCCE (a Short, Self Contained, Correct (Compilable), Example).
But one glaring problem I see that is likely related to your NPE (null pointer exception) is that you're adding the JScrollPane, jsp, to the JPanel, jp2 before jsp has been constructed. As you can see from your code, the jsp is constructed in the ActionListener, and you don't have much control over when this is going to be called. It would seem wiser to construct jsp outside of the ActionListener if you are going to place it in your JPanel regardless of when the ActionListener is called.
adeeb, I'm starting to get the impression that you are just coding, and every single problem you encounter will have you open a thread on this board. Therefore, I would like to ask you to ShowSomeEffort and SearchFirst.
If you would have used the search you would have encountered many similar problems - including at least one from yourself. But let me help you again this time.
Let's take a step by step look at your exception's stack trace:
That tells us that in the main thread (the one that is started for the main method) a NullPointerException (NPE) has occurred.
That NPE is caused by line 1027 in the source of java.awt.Container, in method addImpl. Since this is an API class either you've found a bug (not very likely) or you are using the method wrongly. So let's continue with the next line.
Well another API call, so let's continue again.
Hey, that looks like your own class! In file library.java, at line 341 in the constructor (<init>) you do something that causes the NPE. Looking back one line it is adding something to a Container (JPanel extends Container indirectly). Since the Container itself isn't null (then this would be the first line) it must be the object passed to the add method. Guess you forgot to initialize a component. Again might I add - the last similar problem you posted was almost exactly the same problem. Anyway, continuing.
Any other lines are just where your method call started. In the end, it will most likely end with the main method or the AWT EventQueue.
So now you know how to read stack traces: start from top to bottom until you find a method and class not in the API, and fix the problem there. [ June 15, 2008: Message edited by: Rob Prime ]
Hi, thanks very much for all your efforts and help. I have got the table but when i click the button the old records are not erased and the new once are followed by them. I want to get the records freshly. Please see the table code i have used the DefaultTableModel and i cant understand where to add the functions like revalidate() so that i wont face the above problem
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com