Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Keep additional information about a row in a table

Posted on 2002-06-06
7
Medium Priority
?
226 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 200 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

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…
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 learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
The viewer will learn how to implement Singleton Design Pattern in Java.
Suggested Courses

604 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