Win a copy of Java Database Connections & Transactions (e-book only) this week in the JDBC forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

Data in Swing Tables  RSS feed

 
Ranch Hand
Posts: 473
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
In how many ways can we display data from database? (how many methods exists ?). The rows of the JTable will,obvious, not be fixed beforehand. Can anyone give me idea/codes?

Maki Jav
 
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please rephrase the question.
 
Maki Jav
Ranch Hand
Posts: 473
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I hope that this would be clearer:
Which methods are available in swing api to display data from a database
to a JTable. The point is that number of JTable rows are not hardcoded. So I need to know the methods which I can use for dynamic presentation

Maki Jav
 
Ranch Hand
Posts: 451
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You will probably want to create an implementation of the TableModel interface to wrap the rows in your database. You can do this in several ways:
  • implement TableModel directly
  • extend AbstractTableModel
  • extend DefaultTableModel
  • use DefaulTableModel directly


  • I would recommend first looking at "extend AbstractTableModel". Also, make sure to take a look at the Javadoc and/or the JTable tutorial.
    [ January 24, 2004: Message edited by: Ken Krebs ]
     
    Jason Steele
    Ranch Hand
    Posts: 100
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Yes, you could extend the DefaultTableModel, but if you just want to know how to update a dynamic JTable, you can do the following:

    Then, whenever you want to add rows, do:

    To remove all rows:


    Hope this helps
     
    Maki Jav
    Ranch Hand
    Posts: 473
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Thnaks for replying... So there are four ways I can use JTable to do the task.
    WHy do you think, kerbs, that extending AbstractTableModel is better?
    Thanks for the code Steele
    Maki Jav
     
    Ken Krebs
    Ranch Hand
    Posts: 451
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    I find it to be relatively easy for most of my needs, at least easier than trying to mash DefaultTableModel into something usable or trying to implement the interface myself. That is the purpose of AbstractTableModel, i.e. it provides simple default implementations that you can selectively override. There are situations where DefaultTableModel or a subclass of it might be easier. You have to judge that for yourself.
     
    rubbery bacon. crispy tiny ad:
    how do I do my own kindle-like thing - without amazon
    https://coderanch.com/t/711421/engineering/kindle-amazon
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!