aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes problem in button ActionListener. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "problem in button ActionListener." Watch "problem in button ActionListener." New topic
Author

problem in button ActionListener.

Punit Jain
Ranch Hand

Joined: Aug 20, 2011
Posts: 995
    
    2
hello, i have a code to search from database, when i m printing the db field values, without any ActionListener, my code is working, i mean all the db field values are displaying in the JTable, but when i put the same code on buttonActionListener, my code is not working, but ActionListener is working...
here is my code:


the commented part is which i am adding, without action listner.
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4529
    
    5

The JTable and its TableModel don't know that you have added rows directly to the data vector. Use a DefaultTableModel and its addRow(Vector) method instead.


luck, db
There are no new questions, but there may be new answers.
Punit Jain
Ranch Hand

Joined: Aug 20, 2011
Posts: 995
    
    2
okay..it's working..
but still i have one problem..
i showing me records but not when i am clicking on the button.
after clicking the button, and then i need to minimize the window and than again restore, and then it displaying the records to me.
not just after clicking the button.
Punit Jain
Ranch Hand

Joined: Aug 20, 2011
Posts: 995
    
    2
also i m trying to add scrollbars but they are also not working.
here is what i tried in my above code:

Ranganathan Kaliyur Mannar
Bartender

Joined: Oct 16, 2003
Posts: 1076
    
  10

Punit Jain wrote:also i m trying to add scrollbars but they are also not working.

When is it not working? right from the beginning or only when you click on the button?

I think all the problems are due to the fact that you have not implemented Darryl's suggestion. When the button is clicked, you add the data only to the Vector variable. Where are you telling the JTable that its data has changed?
And now that you are using a DefaultTableModel, why not just use the addRow of that method instead of adding it yourself to the Vector? In case you need that Vector to be used somewhere, you can use the getDataVector method of the model.


Ranga.
SCJP 1.4, OCMJEA/SCEA 5.0.
Punit Jain
Ranch Hand

Joined: Aug 20, 2011
Posts: 995
    
    2

When is it not working? right from the beginning or only when you click on the button?


well, now i m getting nothing, i don't know why, but nothing is to be in the JTable, no scrollbars, no data.


Where are you telling the JTable that its data has changed?

you mean by this:


still nothing is printed.


why not just use the addRow of that method instead of adding it yourself to the Vector

but it's not work for string..i tried like this:
table1.addRow(resultSet.getString("FirstName"));

now i am getting nothing nothing in my JTable, but when i am trying to print records on console, the are printing.
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4529
    
    5

Punit Jain wrote:

why not just use the addRow of that method instead of adding it yourself to the Vector

but it's not work for string..i tried like this:
table1.addRow(resultSet.getString("FirstName"));

You can't get by without reading the API. Apart from which, I already told you which overload of the method to use.
Punit Jain
Ranch Hand

Joined: Aug 20, 2011
Posts: 995
    
    2

I already told you which overload of the method to use.


yes i got that solution, you mean i have to use something like this:


here it works, but i m fetching values for database, so if i am doing directly like this:

it showing me error.
so how i add this:
resultSet.getString("FirstName")
Punit Jain
Ranch Hand

Joined: Aug 20, 2011
Posts: 995
    
    2
okay, i got the records but still has one problem, i have three columns, but my all records are coming in the first column..
i think, there might be any looping problem..
here is part of code in which i make changes:

Punit Jain
Ranch Hand

Joined: Aug 20, 2011
Posts: 995
    
    2
also, when i m clicking on search button, ir showing me records, and then when i am again clicking, it appends new records to earlier records in JTable.
how do i remove the previous data??
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4529
    
    5

Punit Jain wrote:also, when i m clicking on search button, ir showing me records, and then when i am again clicking, it appends new records to earlier records in JTable.
how do i remove the previous data??

Either remove all rows from the data model or construct and set a new model to the table.

Honestly, you can get all this by reading the API. Why don't you try reading it and actually understanding what the various methods do?
Punit Jain
Ranch Hand

Joined: Aug 20, 2011
Posts: 995
    
    2
thank you...

Honestly, you can get all this by reading the API. Why don't you try reading it and actually understanding what the various methods do?


i read API, but it's little bit difficult to me to understand directly from the API.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: problem in button ActionListener.