Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 07-04-2007, 10:21 AM
Member
 
Join Date: Jun 2007
Posts: 95
Felissa is on a distinguished road
Problem with JTable
Hi, it's just a simple question, i like to have a jtable displays just a few columns...

here's the code:
Code:
package ch.svenu.jTableXP; import java.awt.Dimension; import java.util.ArrayList; import javax.swing.JTable; import javax.swing.table.DefaultTableModel; import infrastructure.interfaces.*; public class jT extends DefaultTableModel{ public jT(){ //Faked results ArrayList<Record> myResults = new ArrayList<Record>(); myResults.add(new TempResult("One", "U2", "2007-04-01 08:15:02", "3:42")); myResults.add(new TempResult("Two had found three fours of five", "The Black Eyed Peas", "2007-04-01 08:19:31", "4:07")); myResults.add(new TempResult("Number three", "Jonny Cash", "2007-04-01 08:25:10", "2:58")); //Tableheaders String[] myHeaders = {"Title", "Artist", "Start", "Duration"}; final JTable table = new JTable(myResults, myHeaders); table.setPreferredScrollableViewportSize(new Dimension(500, 70)); } /** * Temporary class that implements Record. * For testing only. * * @author sCHween */ class TempResult implements Record { private String artist; private String duration; private String start; private String title; public TempResult(String t, String a, String s, String d) { artist = a; title = t; start = s; duration = d; } public String getArtist() { return artist; } public String getEffDuration() { return duration; } public String getStartTime() { return start; } public String getTitle() { return title; } } }
Now this line is my problem:
Code:
final JTable table = new JTable(myResults, myHeaders);
Thanks
Felissa
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 07-04-2007, 10:23 AM
Member
 
Join Date: Jun 2007
Posts: 92
Marcus is on a distinguished road
Here is a nice tutorial on the use of JTables:

This will tell you had to add items, create cells and add them, and how else to mess with the container of a jTable.

Greetings.
Marcus
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 07-04-2007, 10:25 AM
Member
 
Join Date: Jun 2007
Posts: 95
Felissa is on a distinguished road
hi, think i made a step forward, but i'm still stuck within.
Code:
package gui; import java.util.ArrayList; import infrastructure.interfaces.Record; import javax.swing.JFrame; import javax.swing.JScrollPane; import javax.swing.JTable; import javax.swing.table.TableModel; public class test{ ArrayList<Record> results; public test() { // // // // // // // // // // // // // // // // // // // // // // // TEMPORARY RESULTS IMPLEMENTATION // // // // // // // // // // // // // // // // // // // // // // // ArrayList<Record> results = new ArrayList<Record>(); results.add(new TempResult("One", "U2", "2007-04-01 08:15:02", "3:42")); results.add(new TempResult("Two had found three fours of five", "The Black Eyed Peas", "2007-04-01 08:19:31", "4:07")); results.add(new TempResult("Number three", "Jonny Cash", "2007-04-01 08:25:10", "2:58")); // Das JTable initialisieren final TableModel rtm = new ReporterTableModel(); final JTable table = new JTable(rtm); final JFrame frame = new JFrame("Reporter "); frame.getContentPane().add(new JScrollPane(table)); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.pack(); frame.setVisible(true); } public static void main(String[] args) { new test(); } // // // // // // // // // // // // // // // // // // // // // // // TEMPORARY CLASS IMPLEMENTATIONS // // // // // // // // // // // // // // // // // // // // // // // /** * Temporary class that implements Record. * For testing only. * * @author brudt1 */ class TempResult implements Record { private String artist; private String duration; private String start; private String title; public TempResult(String t, String a, String s, String d) { artist = a; title = t; start = s; duration = d; } public String getArtist() { return artist; } public String getEffDuration() { return duration; } public String getStartTime() { return start; } public String getTitle() { return title; } }
The ReporterTabelModel.java looks like this:
Code:
package gui; import javax.swing.table.AbstractTableModel; import infrastructure.interfaces.Record; public class ReporterTableModel extends AbstractTableModel{ public int getColumnCount() { return 4; } public int getRowCount() { return 0; } public Object getValueAt(int rowIndex, int columnIndex) { Record result = results.get( rowIndex ); return null; } @Override public String getColumnName(int column) { switch( column ){ case 0: return "Artist"; case 1: return "Title"; case 2: return "Starttime"; case 3: return "Duration"; default: return null; } } }
Now the problem i got - the getValueAt.
There i need access to my ArrayList results and with the columnIndex i have to read the value.
But i couldn't access my results served from test.java.
Thanks
Felissa
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem with jTable that is binded with a table in MySQL Database rajkenneth NetBeans 0 03-29-2008 04:36 PM
Sorting JTable (Vectors) Problem ramapple AWT / Swing 5 02-05-2008 09:54 AM
How to add in a new row in Jtable? Ry4n AWT / Swing 0 01-18-2008 01:26 PM
problem in redrawing JTable abhinav AWT / Swing 0 11-21-2007 10:08 PM
Help with JTable fernando AWT / Swing 1 08-07-2007 07:57 AM


All times are GMT +3. The time now is 12:50 AM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org