Solved

Keep additional information about a row in a table

Posted on 2002-06-06
7
210 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
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
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 
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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:

786 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