Hide a column in JTable

Dear all,
I want to hide a column in JTable object, I already tried resize it to 0 but the effect is not good, I also cannot remove the column, since I need this column for other process.
So, any other good idea besides resizes and remove?
Thank you very much!

I have tried that too, but the column isn't hide, the size is not actually come to 0,...That's because JTable has a default minimum width of 15.... if you want to hide the column, you must set the minwidth as well. For example:
myTable.getColumnModel().getColumn(column_to_hide).setMinWidth(0);
myTable.getColumnModel().getColumn(column_to_hide).setPreferredWidth(0);;o)
V.V.

Similar Messages

  • How to hide the column in JTable

    Hi
    I want to hide a column . But I would be needing the data in that column. ( I have 4 columns )
    I want to hide 4th column
    I have done these steps
    MyTableModel  myTableModel= new  MytableModel(t);
    myTable  = new JTable(myTableModell);                 
    mTable.getColumnModel().removeColumn(myTable.getColumnModel().getColumn(3));When I trying to read the column 1 value it is giving the exception
    myTable.getValueAt(row,3).toString();It is giving the arrayboundexception
    Can anybody tell me what is the correct method to do ?
    Thanks and regards
    Anshuman

    Thanks for reply .
    I have taken the value as the convertRowToModel
    WalterLaan wrote:
    You get an exception because the table doesn't have a column at index anymore, but you can still ask the model.
    table.getModel().getValueAt(table.convertRowToModel(row), 3);
    But it is giving the same error
    java.lang.ArrayIndexOutOfBoundsException: 4 >= 4
         at java.util.Vector.elementAt(Unknown Source)
         at javax.swing.table.DefaultTableColumnModel.getColumn(Unknown Source)
         at javax.swing.JTable.convertColumnIndexToModel(Unknown Source)
         at javax.swing.JTable.getValueAt(Unknown Source)Edited by: techie_india on Jul 6, 2009 10:38 PM

  • Show/hide a column  in JTable

    I want to show/hide columns in JTable
    How is this possible
    Note that columns that are hidden may be showed later
    thanks in advance
    Renjith

    I tried out for this:TableColumn col = jTable.getColumnModel().getColumn( colnum );
    if( col != null )
      col.setPreferredWidth( 0 );
      col.setMaxWidth( 0 );
    }But the column seems to have minimum width which you can't even change with col.setMinWidth( 0 );

  • How to hide a column in a JTable?

    Hi,
    Is it possibile to hide a column in a JTable?
    I mean not to remove, but just to hide the column (I need its values).
    Thanks
    LuKe

    Yup, just set the maximum width to zero:
    TableColumn result = getColumnModel().getColumn(index);
                result.setMinWidth(0);
                result.setPreferredWidth(0);
                result.setWidth(0);
                result.setMaxWidth(0);

  • Hiding a column in jtable made from DefaultTableModel.

    I have made my jtable from DefaultTableModel.
    I want to keep one column in the jtable as hidden storing some data containing neccessary information like the "path of the file"
    which need not be shown to the user.
    Please tell me how I can hide one column in the Jtable.
    please provide siome link or code for the same.
    Tia,
    Sarwa

    dayanandabv wrote:
    [http://search.sun.com/search/onesearch/index.jsp?qt=hide+column%2B+JTable&rfsubcat=&col=developer-forums]
    My thought exactly.
    db

  • How To Delete Columns In JTable?

    Hi,
    I created a JTable and added values through DefaultTableModel. I Have JButton to add columns if need. I have another JButton to remove columns by entering the columns header.. eg: If there are three columns like A,B,C, If i need to remove column "C" means. I just click the remove button and enter the column header in the dilaog box eg: "C". and the columns will deleted. It is working properly. but if i add a new column means the removed columns also getting added and the datas are also in that same column. how delete a column and it's data in a single shot.
    How to add network drivers in a save as dialog box. I have using my code in Windows and also in mac os.
    Thanks in Advance
    by,
    Mohan

    One possibility would be to use a DefaultTableModel to store the data but have JTable access it through your own table model which mapped the columns and altered the column count etc..Why go to all that trouble. If you just want to hide a column, then remove the TableColumn from the TableColumnManager.
    The requirement was to remove the data as well.
    Implementing AbstractTableModel is really less hassle than it looks. Generally you only have to override getColumnName, getValueAt, getRowCount, getColumnCount and (usually) getColumnClass.Nobody said it was difficult, by why reimplement everything from scratch? Just extend DTM to add your new functionality.

  • Add and remove columns from JTable

    Help me please!
    A try to remove column from JTable. It's removed, but when I try to add column in table, then I get all old (removed early) columns + new column....
    I completely confused with it.....
    Here is my code for remove column:
    class DelC implements ActionListener
              public void actionPerformed (ActionEvent e )
                   int [] HowManyColDelete = table.getSelectedColumns();
                   if (HowManyColDelete.length !=0)
                        TableColumnModel tableCModel = table.getColumnModel();
                        for (int i = HowManyColDelete.length-1; i>-1; i--)
                             table.getColumnModel().removeColumn (tableCModel.getColumn (HowManyColDelete [ i ]));
                   else
                          JOptionPane.showMessageDialog(JOptionPane.getRootFrame(), "Column is not selected!");
         }

    It's little ex for me, I just try understand clearly how it's work (table models i mean). Here is code. All action with tables take place through menu items.
    My brain is boiled, I've try a lot of variants of code, but did't get right result :((
    It's code represent problem, which I've describe above. If you'll try remove column and then add it again, it will be ma-a-a-any colunms...
    I understand, that my code just hide columns, not delete from table model....
    But now I have not any decision of my problem...
    Thanks a lot for any help. :)
    import javax.swing.*;
    import java.awt.*;
    import javax.swing.table.*;
    import java.awt.event.*;
    import javax.swing.table.DefaultTableModel;
    class JTableF extends JFrame
         Object [] [] data = new Object [0] [2];
         JTable table;
         DefaultTableModel model;
         String [] columnNames = {"1", "2"};
         TableColumnModel cm;
         JTableF()
              super("Table features");
              setDefaultLookAndFeelDecorated( true );
              setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
              JMenuBar MBar = new JMenuBar();
              JMenu [] menus =  {new JMenu("A"), new JMenu("B")};
              JMenuItem [] menu1 =  {new JMenuItem("Add row"), new JMenuItem("Delete row", 'D'),  new JMenuItem("Add column"), new JMenuItem("Delete column")};
              menu1 [ 0 ].addActionListener(new AddL());
              menu1 [ 1 ].addActionListener(new DelL());
              menu1 [ 2 ].addActionListener(new AddC());
              menu1 [ 3 ].addActionListener(new DelC());
              for (int i=0; i<menu1.length; i++)
                   menus [ 0 ].add( menu1 [ i ]);
              for (int i=0; i<menus.length; i++)
                   MBar.add(menus );
              JPanel panel = new JPanel ();
              model = new DefaultTableModel( data, columnNames );
              table = new JTable (model);
              cm = table.getColumnModel();
              panel.add (new JScrollPane(table));
              JButton b = new JButton ("Add row button");
              b.addActionListener(new AddL());
              panel.add (b);
              setJMenuBar (MBar);
              getContentPane().add(panel);
              pack();
              setLocationRelativeTo (null);
              setVisible (true);
         class DelC implements ActionListener
              public void actionPerformed (ActionEvent e )
                   int [] HowManyColDelete = table.getSelectedColumns();
                   if (HowManyColDelete.length !=0)
                        TableColumnModel tableCModel = table.getColumnModel();
                        for (int i = HowManyColDelete.length-1; i>-1; i--)
                             int vizibleCol = table.convertColumnIndexToView(HowManyColDelete [ i ]);
                             tableCModel.removeColumn (tableCModel.getColumn (vizibleCol));
                        //cm = tableCModel;
                   else
                        JOptionPane.showMessageDialog(JOptionPane.getRootFrame(), "Column is not selected!");
         class AddC implements ActionListener
              public void actionPerformed (ActionEvent e)
                   //table.setColumnModel(cm);
                   Object NewColumnName = new String();
                   NewColumnName = JOptionPane.showInputDialog ("Input new column name", "Here");
                   int i = model.getRowCount();
                   int j = model.getColumnCount();
                   Object [] newData = new Object [ i ];
                   model.addColumn ( NewColumnName, newData);
         class AddL implements ActionListener
              public void actionPerformed (ActionEvent e)
                   int i = model.getColumnCount();
                   Object [] Row = new Object [ i ];
                   model.addRow ( Row );
         class DelL implements ActionListener
              public void actionPerformed (ActionEvent e)
                   int [] HowManyRowsDelete = table.getSelectedRows();
                   if (HowManyRowsDelete.length !=0)
                        for (int k = HowManyRowsDelete.length-1; k>-1; k--)
                             model.removeRow (HowManyRowsDelete[k]);
                   else
                        JOptionPane.showMessageDialog(JOptionPane.getRootFrame(), "Row is not selected!");
         public static void main (String [] args)
              javax.swing.SwingUtilities.invokeLater(new Runnable()
                   public void run()
                        JTableF inst = new JTableF();

  • Problem with Hiding Columns in JTable

    Hi.
    Who knows how to hide column in JTable.
    I try to get column:
    MyTab.getColumnModel().getColumn(i)But there is no methods like SetVisible(false)
    What to DO???

    http://www.google.com/search?hl=en&q=%2Bhide+%2Bcolumn+%2Bjtable&btnG=Google+Search

  • Hidden Columns in JTable

    I wont to hide a elected column in JTable.
    how it to do

    TableColumnModel tcm = table.getColumnModel();
    TableColumn column = tcm.getColumn( modelIndex );
    tcm.removeColumn( column );
    Next time, search the forum first. There are at least a dozen posts asking this question.

  • FireTableStructureChanged losses the Re-ordering of Columns in JTable

    Hello All:
    I have a JTable which uses a TableModel. (I would call PipeFilterTableModel) (The TableModel is based on swingx ). The PipeFilterTableModel takes a Sorter which in turn takes a TableModel.
    One of the filterring mechanism I have is hiding the columns. The way I hide the column is I just reduce the ColumnCount by 1. My method getColumnCount returns one less than the previous filter. I know I can hide the colums by just making the preferred size to zero. But the reason am doing at the TableModel level is becuase i have export and print and other functionality :).
    Anyway, the Table allows Re-ordering of the columns i.e user can move/dragg the columns. But when a ColumnHideFilter is callled I have to use "fireTableStructureChanged" since my table structure is changing (Columns are decreased my one). When that happens I lose the reorderring. Is there anyway I can preserve the reorderring after the firetableStructureChanged ?? I would really appreciate for any help..
    I do have access to JTableHeader (before and after the firetableStructureChanged), but not sure how to reorder the columns after the firetableStructureChanged.
    Thanks
    -Pankaj

    Hi:
    I agree with you guys... that I can remove the column from the TableColumnModel and it would work great. the table won't show the column.
    But in my case I have the export data, print data and all the other functionality written around the tableModel. So as I mentioned previously.. I am using PipeFilterTableModel which filters out data and columns (which are asked to be hidden). So i have to implement the hidden column stuff at the tableModel level.
    So even if I remove the column from Table the export , print and other functionality will get that column (hidden) values from the tableModel.
    As i said I got almost all the things to work except this Reorderring stuff.
    Once I get everything to work fully, I would post it so others can also use it :)
    Thanks
    -Pankaj

  • How can i make hidden column in JTable

    hi, how can i make hidden column in JTable,
    basically i have a ID field in JTable, i have to use this ID , but i also dont want to show this ID in JTable.
    any idea how ??

    staiji its not working
    i did this :
    first :
    TableColumnModel columnModel =
    usersTable.getColumnModel();TableColumn column =
    columnModel.getColumn(1);
    usersTable.removeColumn(column);
    then when i trying to get this :
    Integer userId =
    (Integer)usersTable.getValueAt(UserBrowser.this.usersTa
    le.getSelectedRow(), 0);
    it not give me ID column's value .
    i have a column in JTable like :
    ID | Username | First name | Last name
    i want to hide ID column , but get this ID's value
    when user clicks on JTable row.Hi, if you would read the documentation about JTable.getValueAt(...) you will find, that there is a significant difference between this method and the datamodels getValueAt(...) method. JTables getValueAt(...) method interprets column-index as index in its TableColumnModel - in your TableColumnModel there is no column any longer that holds ID values, therefore you were not able to get it by JTable.getValueAt(...). Do not use these methods for the purpose you want it for - you will also get the wrong values, if the user has repositioned columns - the column index is always interpreted as index in the currently used TableColumnModel and IS NOT A MODELINDEX.
    greetings Marsian

  • SSRS 2005 - Dynamically control the width of columns in Matrix report or Hide any column

    Hi All,
    I just want to hide some column without having white space in Matrix report in SSRS 2005. Although I am aware of that perhaps this feature is not available on SSRS 2005. So, I just want to know if we can handle the width of column dynamically(using expressions)
    in matrix report?
    Please help. Thanks in Advance.
    Regards
    Kumud

    Hi Kumud,
    Based on my test, SSRS is not support column dynamically width. It has property “CanGrow” of text box. If we configure the property to True, it will wraps to next line if needed. In SSRS 2008, we can hide some columns without white space. If possible, I
    recommend you update your SSRS 2005 to SSRS 2008.
    There is a similar issue, you can refer to it.
    http://social.msdn.microsoft.com/Forums/sqlserver/en-US/9e6043f1-c458-4540-be59-d37b02feab8a/dynamic-column-width-for-a-report?forum=sqlreportingservices
    Alternatively, I recommend you that submit a wish to the Microsoft Connect at
    https://connect.microsoft.com/SQLServer/Feedback. Your feedback is valuable for us to improve our products and increase the level of service provided.
    Regards,
    Alisa Tang
    Alisa Tang
    TechNet Community Support

  • How to show or Hide Generic Column in a regular report

    Hi All,
    I have created report based on "SQL query (pl/sql function body returning sql query). It returns columns based on some conditions. I have total 60 generic columns like (COL1,COL2....COL60) but it returns 18 or 20 columns based on my conditions, how can I hide the columns that I don't needed. My column heading is based on function return by ':' separated. My function returns number of columns also. Is there any we I can show only those columns which contains data. My report is exactly similar to the default "SQL query (pl/sql function body returning sql query). I didn't find any logic how they are doing this show and hide. I appreciate any ones help.
    Thanks,

    Hi there,
    Somehow you need to find out how many columns your dynamic select will return (by what you said it seems that your procedure returns this information). Then store that number in a hidden page item, say Pnn_COUNT.
    Then, for the 19th and 20th columns in the report add these conditions:
    Column 19: :Pnn_COUNT >= 19
    Column 20: :Pnn_COUNT >= 20
    I hope this helps.
    Luis

  • How to hide Actions Column in Table

    Hi All,
    I have a simple requirement: I am showing a table (items)
    - the "Actions" column (Column with Buttons to Edit and Delete a particualr row) must not be show -> no changes to the table are allowed (I need to hide/ disable this column)
    How can I hide this column od the table?
    I have found out that the field is called thtmlb_oca and that htere is a getter method get-thtmlb_oca. However, the method does not contain coding and I do not know how to HIDE this field/ column...
    Please help me here..
    Thanks, Johannes

    Hi Johannes,
    To remove the column completely,
    you need to comment this line in the method GET_TABLE_LINE_SAMPLE of the Table View Context node class.
    TYPES: BEGIN OF line,
    *  thtmlb_oca  type  crm_thtmlb_one_click_action.
      INCLUDE TYPE xxxx.
      TYPES:  END OF line.
    Disabling can be controlled in the method GET_OCA_T_TABLE of the same class by putting code to delete the button.
    LOOP AT  rt_actions ASSIGNING <fs_actions>.
          <fs_actions>-active  = abap_false.
        ENDLOOP.
    Regards,
    Masood Imrani S.

  • Hide a column in one view, but show in other

    Hi all.
    I need to hide a column on "Table" view, but column needs to show up on "Pivot table".
    I know we can hide it on pivot ( exclude It ) and show on table, but I want to know if reverse is possible.
    This is needed because I am doing a view selector for writeback. And I dont want to display all the columns on writeback table view. But it needs to be there on Pivot table.
    Please let me know if it is possible.
    Thanks.
    Vinay

    Yes we can do that.
    Check on the "Hide" in the column format tab of the column that you need to display in the table lay out.
    Now dupliate the same view and in the pivot table column intially you will not see the column displayed.
    Now in the properties check on "hidden" in the "format headings" and you wont see it still and now uncheck the"hidden" and you shoud be able to see the column displayed in the pivot view
    In this way you will have the column hidden in the table view and displayed in the pivot table.
    Hope it helps
    Prash

Maybe you are looking for