Solved

Keep additional information about a row in a table

Posted on 2002-06-06
7
202 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
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
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 learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
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…

743 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

13 Experts available now in Live!

Get 1:1 Help Now