Solved

Keep additional information about a row in a table

Posted on 2002-06-06
7
215 Views
Last Modified: 2010-03-31
Hi,
I want to keep information about a row in a table model that doesn't need to be displayed.
Foe example, I have:

class Person
{
  String name;
  String address;
  String phone:
  int status;
}

I want to show a table of Persons when status is not displayed:

Name |  Address  |  Phone #  |
______________________________


I want the information to be valid even when the table is sorted.
I don't want to use another class such as:

class NameStatus
{
  String name;
  int status;

  public String toString()
  {
    return name;
  }
}

And use it in the name field.

Any idea?
0
Comment
Question by:s_lavie
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 92

Expert Comment

by:objects
ID: 7058742
Not sure I understand your problem. Your table model just needs to keep an array/list of Person objects, and return the relevant data for each column. The fact that your Peron class contains additional info doesn't cause a problem.
0
 
LVL 2

Author Comment

by:s_lavie
ID: 7058790
I use:
DefaultTableModel tableModel;
tableModel.addRow(rowData);

Where rowData is a Vector contains the fields to be displayed in the table (status field is not there).
0
 
LVL 92

Accepted Solution

by:
objects earned 50 total points
ID: 7058802
Define you own TableModel wrapping your array or Person objects, something like:

public class PersonTableModel extends AbstractTableModel
{
   private Person[] Rows;
 ...
}

I'll leave the rest to you as an exercise :)
Here's a link that may help:
http://java.sun.com/docs/books/tutorial/uiswing/components/table.html#data

And if you have any questions then feel free to ask :-)
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Expert Comment

by:laax
ID: 7121614
Hi,

   You can just load all the columns in the JTable and set minWidth, maxWidth and width properties of required(to hide) column's TableColumn object set to zero.

   For Ex, in your case...get the TableColumn object for status column and set the minWidth, maxWidth and width to zero.

Laax.
0
 
LVL 5

Expert Comment

by:vemul
ID: 7888053
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

- points to objects

Please leave any comments here within the
next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER !

vemul
Cleanup Volunteer
0
 
LVL 92

Expert Comment

by:objects
ID: 7888830
thanks for that :-)
0
 
LVL 2

Author Comment

by:s_lavie
ID: 7888842
sorry for the late response ;-)
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
maven module vs maven project 3 73
Eclipse with various Java releases 7 50
web project error add remove 1 54
Netbeans and org.apache.commons.lang3 issue 3 27
For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question