Solved

Keep additional information about a row in a table

Posted on 2002-06-06
7
205 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Application launch issue with Apache Tomcat 5 19
Error with Java/Cache JDBC Classpath 2 30
ArrayIndexOutOfBoundException 9 66
varialbe initialization 11 30
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

914 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now