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.

Similar Messages

  • 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

  • Show hidden columns in a JTable

    Hi,
    I have a requirement for hiding some columns of a JTable and showing them back based on user actions.
    I have gone through some topics about hiding columns. which can be done by table.removeColumn();
    But when I use table.addColumn(); it adds the column at the end of the table.It should add in the same location as the previous column.
    How to show /reveal the hidden column back?.

    * Hide_Columns.java
    * This code contains a table model that allows you to
    * specify the columns to be hidden in a boolean array.
    * To use the model:
    *       model = new MyTableModel(data, columnNames);
    *       table.setModel(model);
    * The most important method in the model is "getNumber()", which converts a column number
    * into the number corresponding to the data to be displayed.
    * Visible columns can be dynamically changed with
    * model.setVisibleColumns(0, column0.isSelected());
    import java.awt.*;
    import java.awt.event.*;
    import java.util.*;
    import javax.swing.*;
    import javax.swing.table.*;
    public class Hide_Columns extends JFrame {
        public Hide_Columns() {
            setTitle("Hide columns");
            setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
            model = new MyTableModel(data, columnNames);
            table.setModel(model);
            getContentPane().add(new JScrollPane(table), BorderLayout.CENTER);
            for( int i=0; i<4; i++ ){
                final JCheckBox columnX = new JCheckBox("Column "+i);
                columnX.setSelected(true);
                final int col = i;
                columnX.addActionListener(new ActionListener() {
                    public void actionPerformed(ActionEvent evt) {
                        model.setVisibleColumns(col, columnX.isSelected());
                toolBar.add(columnX);
            getContentPane().add(toolBar, BorderLayout.NORTH);
            setSize(400,300);
            setLocationRelativeTo(null);
            model.addRow(new Object[]{null,null,null,null});
            model.setValueAt("test0",0,0);
            model.setValueAt("test1",0,1);
            model.setValueAt("test2",0,2);
            model.setValueAt("test3",0,3);
        public static void main(String args[]) { new Hide_Columns().setVisible(true); }
        private JTable table = new JTable();
        private  JToolBar toolBar = new JToolBar();
        private   MyTableModel model;
        /** This is the data of the table*/
        private  Vector<Object> data = new Vector<Object>();
        /** Column names */
        Vector<String> columnNames = new Vector<String>();{
            columnNames.addElement("0");
            columnNames.addElement("1");
            columnNames.addElement("2");
            columnNames.addElement("3");
    class MyTableModel extends DefaultTableModel {
        /** Shows which columns are visible */
        private   boolean[] visibleColumns = new boolean[4];{
            visibleColumns[0] = true;
            visibleColumns[1] = true;
            visibleColumns[2] = true;
            visibleColumns[3] = true;
        public MyTableModel(Vector<Object> data, Vector<String> columnNames){
            super(data, columnNames);
        protected void setVisibleColumns(int col, boolean selection){
            visibleColumns[col] = selection;
            fireTableStructureChanged();
         * This function converts a column number of the table into
         * the right number of the data.
        protected int getNumber(int column) {
            int n = column;    // right number
            int i = 0;
            do {
                if (!(visibleColumns)) n++;
    i++;
    } while (i < n);
    // When we are on an invisible column,
    // we must go on one step
    while (!(visibleColumns[n])) n++;
    return n;
    // *** METHODS OF THE TABLE MODEL ***
    public int getColumnCount() {
    int n = 0;
    for (int i = 0; i < 4; i++)
    if (visibleColumns[i]) n++;
    return n;
    public Object getValueAt(int row, int column) {
    return super.getValueAt(row, getNumber(column));
    public void setValueAt(Object obj, int row, int column) {
    super.setValueAt(obj, row, getNumber(column));
    public String getColumnName(int column) {
    return super.getColumnName(getNumber(column));

  • JTable, stopping navigation into hidden columns?

    Hello,
    In JTable I have done .setPreferedWidth(0) along with every other width setting =0; I did this to hide columns which are necessary but uninformative to the user like primary key ids. The problem is that you can still hit tab, shift-tab, and right arrow which will put the "focus" in the hidden columns, effectively 'losing' the cursor for the user.
    How do I fix this?
    I've tried using focusLost listeners but they don't fire every time I need. When a user starts editing a cell by arrow-keying over then just typing (never double clicking), then subsequently exiting the cell using the tab key or right arrow, I don't get the event to fire.
    I've also tried a KeyListener, but this doesn't work every time I'd expect.
    Any help would be greatly appreciated!!!

    There is a way to make the navigation keys skip the column with a width of zero, but the real question is how badly do you want to get it done? If you want it bad enough, then I suggest you override JTable's processKeyBinding method and for every navigation key (up, down, left, right, tab, shift-tab, home, end, etc., etc., etc.) check to see if it lands on such a column, if so manually move to the non-zero column in the direction of the key -- otherwise, let JTable's own processKeyBinding method consume the event.
    ;o)
    V.V.
    PS: If you are one of those people who don't like to go down to the low level, you can add as many InputMap/ActionMap to take care of these keys.

  • 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

  • Custom table model, table sorter, and cell renderer to use hidden columns

    Hello,
    I'm having a hard time figuring out the best way to go about this. I currently have a JTable with an custom table model to make the cells immutable. Furthermore, I have a "hidden" column in the table model so that I can access the items selected from a database by their recid, and then another hidden column that keeps track of the appropriate color for a custom cell renderer.
    Subject -- Sender -- Date hidden rec id color
    Hello Pete Jan 15, 2003 2900 blue
    Basically, when a row is selected, it grabs the record id from the hidden column. This essentially allows me to have a data[][] object independent of the one that is used to display the JTable. Instinctively, this does not seem right, but I don't know how else to do it. I know that the DefaultTableModel uses a Vector even when it's constructed with an array and I've read elsewhere that it's not a good idea to do what I'm trying to do.
    The other complication is that I have a table sorter as well. So, when it sorts the objects in the table, I have it recreate the data array and then set the data array of the ImmutableTableModel when it has rearranged all of the items in the array.
    On top of this, I have a custom cell renderer as well. This checks yet another hidden field and displays the row accordingly. So, not only does the table sort need to inform the table model of a change in the data structure, but also the cell renderer.
    Is there a better way to keep the data in sync between all of these?

    To the OP, having hidden columns is just fine, I do that all the time.. Nothing says you have to display ALL the info you have..
    Now, the column appears to be sorting properly
    whenever a new row is added. However, when I attempt
    to remove the selected row, it now removes a seemingly
    random row and I am left with an unselectable blank
    line in my JTable.I have a class that uses an int[] to index the data.. The table model displays rows in order of the index, not the actual order of the data (in my case a Vector of Object[]'s).. Saves a lotta work when sorting..
    If you're using a similar indexing scheme: If you're deleting a row, you have to delete the data in the vector at the INDEX table.getSelectedRow(), not the actual data contained at
    vector.elementAt(table.getSelectedRow()). This would account for a seemingly 'random' row getting deleted, instead of the row you intend.
    Because the row is unselectable, it sounds like you have a null in your model where you should have a row of data.. When you do
    vector.removeElementAt(int), the Vector class packs itself. An array does not. If you have an array, when you delete the row you must make sure you dont have that gap.. Make a new array of
    (old array length-1), populate it, and give it back to your model.. Using Vectors makes this automatic.
    Also, you must make sure your model knows the data changed:
    model.fireTableDataChanged(); otherwise it has no idea anything happened..
    IDK if that's how you're doing it, but it sounds remarkably similar to what I went thru when I put all this together..

  • 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

  • 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 );

  • Auto size columns but with hidden columns

    I want to hide some columns for interal use with the following statements:
    jTable.getColumnModel().getColumn(i).setMaxWidth(0);
    jTable.getColumnModel().getColumn(i).setMinWidth(0);
    jTable.getColumnModel().getColumn(i).setPreferredWidth(0);
    Now I find that the widths of hidden columns become not zero.
    But I still want to auto-size the columns, so I add
    setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS);
    Then I find that the widths of hidden columns become not zero.
    Could anyone tell me how to auto size the columns while keeping the hidden columns with zero widths?
    Thanks!

    If you want to hide columns then remove them from the TableColumnModel. The data is not removed, the columns are just not painted. Here is an example:
    http://forum.java.sun.com/thread.jsp?forum=31&thread=411506

  • Apex_application.g_f01 picking up value of hidden column

    i have a report with a apex_item.checkbox using the id 1 and a hidden column. for some reason my pl/sql code that loops through apex_application.g_f01 picks up the value of the hidden column as well. why is this? is this a known bug?
    i managed to get my code working by using id 2.

    report code
    select ename,
    apex_item.checkbox(1,ename,null) sel,
    'RED' COLOUR
    from emp
    order by ename
    process
    FOR I in 1..APEX_APPLICATION.G_F01.COUNT LOOP
    //i insert into a test table to view results
    END LOOP;
    the above works fine until i change the COLOUR column from a standard column to a hidden column. Then for some reason the apex_application.g_f01 then includes the values of all ticked boxes plus all the values in the COLOUR column.

  • Excel Upload with Hidden Column

    Hi Gurus-
    Can you upload Excel file with hidden column and get the function to read values in hidden column? If yes, could you please guide me how?
    I am using ALSM_EXCEL_TO_INTERNAL_TABLE
    Any help will be highly appreciated.
    Thanks in advance!

    Hi,
    Have a look at program RSDEMO01 (available in the controls examples of the workbench). It demonstrates an OLE connection to Excel.
    To know which excel objects, methods and properties to use it is a good idea to use the excel macro recorder - just do what you want your program to do and then translate the resulting VB code to ABAP OLE.
    For the import of the clipboard data you can use CL_GUI_FRONTEND_SERVICES=>CLIPBOARD_IMPORT. In the result table, iirc, there  is one line for each imported line and within the line the cell values are separated by tab. So there is some work left - it might be a good idea t import the data column by column.
    It has been some time when I did this for a former client of me - so unfortunately I do not have the code any more.
    Regards, Gerd Rother

  • How do I get a hidden column to show in a library?

    I am having an odd behavior on one of my site columns, and am hoping someone might be able to shed some light on this for me. I have just built a content type hub. Also created some site columns....I have one particular column (which is a choice type), that
    is hidden at the parent content type level. I see this hidden column each time i view the settings of any content type that inherits from the parent content type. However, when I add these child content types to a library, I no longer see the hidden column.
    I don't understand why this is the case. 
    Can anyone shed some light on this for me? Is this the way it is designed to work in SharePoint?
    Update: When I view the inheriting content type from the hub, I see the hidden column. But if I view the same content type from within my site, I do not see the hidden column. Is this a publishing issue? Or is this by design in SharePoint?

    That definitely does not sound like design.  Have you tried editing the content type on the library level NOT the hub level?  You should be able to set the hidden status to display within the Content Type section on the library.
    If that doesn't work, it'll be worth looking at something like SharePoint Manager to open up the column and inspect its properties.
    Steven Andrews
    SharePoint Business Analyst: LiveNation Entertainment
    Blog: baron72.wordpress.com
    Twitter: Follow @backpackerd00d
    My Wiki Articles:
    CodePlex Corner Series
    Please remember to mark your question as "answered" if this solves (or helps) your problem.

  • How to set different renderers to different cells in same column of JTable?

    Hello Friends,
    I need your help again...
    Does any body knows, how to set different renderer's for different cells of same column in JTable..??
    For ex.
    Col1 Col2 Col3 Col4
    A       A       A      A
    A       A       A      B
    A       A       A      C
    A       A      A       D
    Where A B C D would be different Renderers.  I want set exactly same ,,, ie. one column with different renderer at different cell positions..
    Right now i m setting renderer using statement bellow :
    table.getColumnModel().getColumn(int).setCellRenderer(rederer_Instance);But with this, effect in the last renderer is applicable whole column....
    Can any body help me out ?????????
    please refer this thread for similar kind of discussion...
    http://forums.sun.com/thread.jspa?forumID=57&threadID=571445Thanks
    Suyog

    Please refer to the first reply of [this thread|http://forums.sun.com/thread.jspa?forumID=57&threadID=571445] for the answer. If you have a specific problem implementing it, post you code with a specific question.

  • Total, Subtotal of a hidden column in an ALV grid

    I have a requirement for an ALV grid where I have to use a custom formula for a column's total and subtotal.
    This value is a function of another column which is hidden (No_out = 'X').
    I am unable to access the total and subtotal of this hidden column . I am able to access this only when I unhide the column in the field catalog.
    THis is how I access the total and subtotal of the GRID. I use oops ALV of the class CL_GUI_ALV_GIRD.
    call method o_grid->get_subtotals
        importing
          ep_collect00 = total
          ep_collect01 = subto.
      assign total->* to <ftotal>.
      assign subto->* to <fsubto>.
    I thought I would manipulate <ftotal>-mycolumn and <fsubto>-mycolumn . But both these are functions of a hidden column
    and <ftotal>-hiddencolumn and <fsubto>-hiddencolumn is always empty unless I unhide them. I cannot display these columns to users as they are just logical columns of a dynamic internal table I have built.  :-s

    HI,i have the same issue, how did you solve it?
    Regards.

  • MMS Hidden columns appearing in Document Library Settings / Column list

    Hello all,
    Before you read this please be aware that I have found a resolution (that might be helpful to others) but I am wondering if anyone else has experienced the same thing and the cause.
    Our scenario is as follows:
    We use a Content Type hub
    Most Content Types include one or more Managed metadata columns
    The MMS Notes (hidden) columns (e.g. mms_column_name_0) have appeared on the 'Document Library Settings page under 'Columns' for 2 document libraries only. They appear under the actual name of the column (e.g. mms_column_name).
    They are NOT visible to the user however (i.e. they are not selectable to be used in a view)
    Looking at SharePoint Manager the mms Notes column's are marked as being Hidden = false. Altering this to true has the desired effect.
    But has anyone else experienced the same issue as I'm inquisitive as to the cause.
    The only thing I can think of that caused this to happen was us using 'Metadata navigation settings' (which allows you to configure navigation hierarchies) for the first time on one of the 2 Doc Libs effected . However, on testing it on other document
    libraries the unhiding of columns has not occurred.
    Can anyone shed any why this may have occurred?
    Jason

    Hi jasonl27,
    this behaviour:
    This is by design. Two separate lists do not have any type of relationship established to distinguish that the
    columns are the same. For example, take an arbitrary column called "Position" being created on two different custom lists. Because the column Position is a custom column created
    in the list, it has no mapping to other lists. The "Position"
    in one list could refer to a title of a person
    in one list, or a physical location on a different list. SharePoint cannot tell if these two items are the same or completely different. As a result, a new column name is added when we move the item.
    perhaps you may try to do these steps:
    $site = Get-SPSite -Identity "http://......../"
    $web = $site.RootWeb
    $field=$web.Fields["column name"]
    $field.Update($true)
    $field.Hidden= "True"
    $web.Dispose()
    $site.Dispose()
    Regards,
    Aries
    Microsoft Online Community Support
    Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.

Maybe you are looking for

  • What is the diffrence between SCHEMA_LIST and SCHEMA_EXPR

    I want to export schemas from a list what is the difference between: dbms_datapump.metadata_filter(dph, 'SCHEMA_LIST', 'IN (' || schema_names || ')' ); and dbms_datapump.metadata_filter(dph, 'SCHEMA_EXPR', 'IN (' || schema_names || ')' ); I can not r

  • Wipe BBID (lost password / recovery answer Android/iPhone)

    Does anyone know how I can wipe my BBID using windows, I used to have a Blackberry years ago, I've since forgotten my BBID password and I must have typed my security answer wrong back then, I am now using a iPhone and have no ability to wipe my accou

  • Can't print large images

    Hello, I'm printing a set of large, stiched images. There are thirty-eight images in the set and the first eight went fine. Suddenly I can't print from CS3. I choose print and the print dialog comes up. It is up for a minute or two (normal with the f

  • Q: Auto file naming in TextEdit possible?

    I've just come over from the 'Dark Side' having been freed from the 'MicroSith' Empire and I'm really enjoying my two new Macs. I'm taking some extra time to set it up like I want. I'm interested in productivity. Is there a way to cause TextEdit to t

  • Modification in WAD (BI70)

    hi experts, i use wad to show my report, i want to change the value in a field to another text, for example, the table is: field1   field2  field3 a1       1        b1 a2       0        b2 a3       1        b3 i want to change it to display field1