6 Replies - 2201 Views - Last Post: 24 July 2012 - 01:05 PM Rate Topic: -----

#1 roona  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 04-April 10

how to hide column in jtable

Posted 23 July 2012 - 02:19 PM

I create JTable using DefaultTableModel
Can you help me how to hide one column from my JTable
Is This A Good Question/Topic? 0
  • +

Replies To: how to hide column in jtable

#2 CasiOo  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1274
  • View blog
  • Posts: 2,836
  • Joined: 05-April 11

Re: how to hide column in jtable

Posted 23 July 2012 - 02:53 PM

You could remove the column and then add it again later. If you made your own tablemodel (extending AbstractTableModel), you could adjust the column count and make sure the right values get returned by the method getValueAt
Was This Post Helpful? 1
  • +
  • -

#3 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8315
  • View blog
  • Posts: 31,836
  • Joined: 06-March 08

Re: how to hide column in jtable

Posted 23 July 2012 - 03:40 PM

View PostCasiOo, on 23 July 2012 - 05:53 PM, said:

If you made your own tablemodel (extending AbstractTableModel), you could adjust the column count and make sure the right values get returned by the method getValueAt

That is the approach I would use
Was This Post Helpful? 0
  • +
  • -

#4 roona  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 04-April 10

Re: how to hide column in jtable

Posted 24 July 2012 - 12:43 PM

View PostCasiOo, on 23 July 2012 - 02:53 PM, said:

You could remove the column and then add it again later. If you made your own tablemodel (extending AbstractTableModel), you could adjust the column count and make sure the right values get returned by the method getValueAt

but I didn't create my own AbstractTableModel ,I create JTable using DefaultTableModel but I tried much to hidding column and don't work...:(.Please help me how to hide column
sorry for mistakes,I didn't speak english very well
Was This Post Helpful? 0
  • +
  • -

#5 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8315
  • View blog
  • Posts: 31,836
  • Joined: 06-March 08

Re: how to hide column in jtable

Posted 24 July 2012 - 12:48 PM

So extend AbstractTableModel, shouldn't be difficult if you already built your table
I even have a tutorial about it

http://www.dreaminco...h-a-tablemodel/
Was This Post Helpful? 0
  • +
  • -

#6 roona  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 04-April 10

Re: how to hide column in jtable

Posted 24 July 2012 - 12:51 PM

but data in my JTable are displayed from my database with query select * from ....
and DefaultTableMode is useful for that
Was This Post Helpful? 0
  • +
  • -

#7 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8315
  • View blog
  • Posts: 31,836
  • Joined: 06-March 08

Re: how to hide column in jtable

Posted 24 July 2012 - 01:05 PM

View Postroona, on 24 July 2012 - 03:51 PM, said:

but data in my JTable are displayed from my database with query select * from ....
and DefaultTableMode is useful for that

In that it will be even easier with your own model that extends AbstractTableModel

After all a DefaultTableModel is just an extension of AbstractTableModel that use Vector to store the data

/**
 * This is an implementation of <code>TableModel</code> that
 * uses a <code>Vector</code> of <code>Vectors</code> to store the
 * cell value objects.
 * <p>
 * <strong>Warning:</strong> <code>DefaultTableModel</code> returns a
 * column class of <code>Object</code>.  When
 * <code>DefaultTableModel</code> is used with a
 * <code>TableRowSorter</code> this will result in extensive use of
 * <code>toString</code>, which for non-<code>String</code> data types
 * is expensive.  If you use <code>DefaultTableModel</code> with a
 * <code>TableRowSorter</code> you are strongly encouraged to override
 * <code>getColumnClass</code> to return the appropriate type.
 * <p>
 * <strong>Warning:</strong>
 * Serialized objects of this class will not be compatible with
 * future Swing releases. The current serialization support is
 * appropriate for short term storage or RMI between applications running
 * the same version of Swing.  As of 1.4, support for long term storage
 * of all JavaBeans<sup><font size="-2">TM</font></sup>
 * has been added to the <code>java.beans</code> package.
 * Please see {@link java.beans.XMLEncoder}.
 *
 * @version %I% %G%
 * @author Philip Milne
 *
 * @see TableModel
 * @see #getDataVector
 */
public class DefaultTableModel extends AbstractTableModel implements Serializable {

//
// Instance Variables
//

    /**
     * The <code>Vector</code> of <code>Vectors</code> of 
     * <code>Object</code> values.
     */
    protected Vector    dataVector;

    /** The <code>Vector</code> of column identifiers. */
    protected Vector    columnIdentifiers;



so you can simply extend the DefaultTableModel
worst case, your Vector won't be used

This post has been edited by pbl: 24 July 2012 - 01:25 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1