customizing JTable
  Home FAQ Contact Sign in
comp.lang.java.help only
 
Advanced search
POPULAR GROUPS

more...

comp.lang.java.help Profile…
 Up
customizing JTable         


Author: thufir
Date: Jul 6, 2008 07:09

I've been looking at:

http://www.netbeans.org/kb/articles/mysql-client.html#db08

A DefaultTableModel uses

protected Vector dataVector
The Vector of Vectors of Object values.

for the data? So, that's where the data is, in dataVector?

//carTable is a JTable
carTable.setModel(CarTableModel.getInstance());

Should carTable now show data, providing that carTable.getDataVector()
returns data?

thanks,

Thufir
6 Comments
Re: customizing JTable         


Author: Thufir
Date: Jul 6, 2008 09:25

On Jul 6, 7:14 am, Lew lewscanon.com> wrote:
[...]
>> //carTable is a JTable
>> carTable.setModel(CarTableModel.getInstance());
>
>> Should carTable now show data, providing that carTable.getDataVector()
>> returns data?
>
> How would the getInstance() fill the data?
>
> Why not use a constructor instead of reflection? You obviously already know
> the class, so it seems like reflection is not needed.
[...]

I wasn't aware that I was using reflection. Is:

http://java.sun.com/javase/6/docs/api/java/util/Calendar.html#getInstance()

reflection?

I only want one CarTableModel, so it's a Singleton.

The CarTableModel.getInstance() returns the only CarTableModel.

If it matters, I can make the constructor public and instead have:
Show full article (1.12Kb)
no comments
Re: customizing JTable         


Author: Roland de Ruiter
Date: Jul 6, 2008 09:37

On 6-7-2008 16:09, thufir wrote:
> I've been looking at:
>
> http://www.netbeans.org/kb/articles/mysql-client.html#db08
>
> A DefaultTableModel uses
>
> protected Vector dataVector
> The Vector of Vectors of Object values.
>
> for the data? So, that's where the data is, in dataVector?
>

For a DefaultTableModel instance? Yes.
> //carTable is a JTable
> carTable.setModel(CarTableModel.getInstance());
>
>
> Should carTable now show data, providing that carTable.getDataVector()
> returns data?
Show full article (1.28Kb)
no comments
Re: customizing JTable         


Author: Mark Space
Date: Jul 6, 2008 10:09

thufir wrote:
>
> A DefaultTableModel uses
>
> protected Vector dataVector
> The Vector of Vectors of Object values.
>
> for the data? So, that's where the data is, in dataVector?

I didn't follow the tutorial carefully, but you still have to set the
dataVector field to something. See the setDataVector() method.
>
> //carTable is a JTable
> carTable.setModel(CarTableModel.getInstance());
>

I have no idea what "getInstance()" is, did you add it yourself? It's
not in any of the docs that I can find.
>
> Should carTable now show data, providing that carTable.getDataVector()
> returns data?
Show full article (0.71Kb)
no comments
Re: customizing JTable         


Author: thufir
Date: Jul 6, 2008 19:35

On Sun, 06 Jul 2008 12:52:23 -0400, Lew wrote:
> If you provide an SSCCE maybe I'll get less confused.

Kinda long:

thufir@arrakis:~$
thufir@arrakis:~$ cat NetBeansProjects/arrays/src/a00720398/model/
CarTableModel.java
package a00720398.model;

import java.sql.*;
import java.util.*;
import java.util.logging.*;
import javax.swing.table.*;

@SuppressWarnings({"serial"})
public class CarTableModel extends DefaultTableModel {

private static final TableModel INSTANCE = new CarTableModel();
Show full article (2.45Kb)
1 Comment
Re: customizing JTable         


Author: Mark Space
Date: Jul 7, 2008 00:23

thufir wrote:
> public class CarTableModel extends DefaultTableModel {
>
> private static final TableModel INSTANCE = new CarTableModel();
>
> public class CarTableData {
>
> private static final CarTableData INSTANCE = new CarTableData();

Personally, these static variables weird me out. What if you need to
display two tables? Say the user is comparing two lists of cars, one
list from cars in rows 100-110 of the database (the cheap cars) and the
other table shows rows 340-350? How do you do that when there can only
be one table ever?

I think you should just get rid of the "INSTANCE" field in both cases,
and just call "new" on the class like a normal class. You should be
able to just make a table model and drop it into the JFrame's JTable,
kinda like this:

package jtabletest;
Show full article (1.93Kb)
no comments
Re: customizing JTable         


Author: thufir
Date: Jul 7, 2008 01:28

On Sun, 06 Jul 2008 18:37:58 +0200, Roland de Ruiter wrote:
> Nope. If carTable is an instance of class JTable,
> carTable.getDataVector()
> won't compile, because JTable doesn't have a method getDataVector().

Right, that was a typo
-- pardon. I meant carTable.getModel
().getDataVector().

-Thufir
no comments

RELATED THREADS
SubjectArticles qty Group
Re: UPDATE Sprint Dumps Needy Customers - Gismodo - READ THIS - Interesting Customer Service Modelalt.cellular.sprintpcs ·