• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

problem in button ActionListener.

 
Ranch Hand
Posts: 1143
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Bartender
Posts: 5167
11
Netbeans IDE Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Punit Jain
Ranch Hand
Posts: 1143
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 1143
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
also i m trying to add scrollbars but they are also not working.
here is what i tried in my above code:

 
Bartender
Posts: 1104
10
Netbeans IDE Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Punit Jain
Ranch Hand
Posts: 1143
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


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
Posts: 5167
11
Netbeans IDE Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 1143
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


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
Posts: 1143
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 1143
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 5167
11
Netbeans IDE Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 1143
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic