This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes Data in Swing Tables Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Data in Swing Tables" Watch "Data in Swing Tables" New topic
Author

Data in Swing Tables

Maki Jav
Ranch Hand

Joined: May 09, 2002
Posts: 435
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


Help gets you when you need it!
Jason Steele
Ranch Hand

Joined: Apr 25, 2003
Posts: 100
Please rephrase the question.


An egg is a chicken's house!
Maki Jav
Ranch Hand

Joined: May 09, 2002
Posts: 435
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
Ken Krebs
Ranch Hand

Joined: Nov 27, 2002
Posts: 451
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 ]

    kktec<br />SCJP, SCWCD, SCJD<br />"What we observe is not nature itself, but nature exposed to our method of questioning." - Werner Heisenberg
    Jason Steele
    Ranch Hand

    Joined: Apr 25, 2003
    Posts: 100
    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

    Joined: May 09, 2002
    Posts: 435
    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

    Joined: Nov 27, 2002
    Posts: 451
    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.
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: Data in Swing Tables
     
    Similar Threads
    Hibernate/IBatis/JPA for Stand alone applications
    how many data can be set in context ,session ,and request ? 500M is OK ?Thank you!
    JTable for accepting data
    how many data can be set in context ,session ,and request ? 500M is OK ?Thank you!
    add a bean to many servlets which share their data