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

Similar Messages

  • Hiding a column in JTable

    Hi,
    I want to hide a column when i select Hide option from a popup menu and
    again bring it back when i select show option again from the popup menu.
    How to get this done?

    Hi!
    The simplest way to do that, is to set the column width to 0 for hiding and back to its normal size to show it again.
    Cheers
    K.

  • Last column in JTable detaches from edge of JScroll Pane

    i have a JTable in a JScrollPane which is in half of a JSplitPane.
    The table has autoResizeMode set to AUTO_RESIZE_OFF to make the horizontal scrollbar appear.
    However, when i resize the split pane to make the table bigger, the edge of the last column no longer runs to the edge of the JScrollPane, it detaches.
    What i need is for the last column to be able to expand infinitely, but when the split pane size is being reduced, for the columns to disapear off the edge of the scroll pane and the scroll bar to appear. This is a mix of AUTO_RESIZE_OFF and AUTO_RESIZE_LAST_COLUMN.

    I too had this problem. I had a method that would set the minimum size of columns based on the data within the table, etc. It seems that when you do anything to set the pref or min size of a column the horizontal scrolling gets all messed up. How I solved the problem is to basically swap the autosize method on the table back and forth whenever the parent component of the table is resized. Some example code follows.
    First, add a inner class ComponentListener on the parent component the table is in (a frame in my case, I guess this could be the scroll pane too?):
    _myFrame.addComponentListener( new ComponentAdapter()
        public void componentResized(ComponentEvent e)
            _parentResized();
    });Now the _parentResized() method that is called by the inner class looks like this:
    * Our parent container component was resized, so update how the table's
    * columns are layed out.
    private void _parentResized()
        TableColumnModel tcm = _table.getColumnModel();
        int colWidth = 0;
        for( int j = 0; j < tcm.getColumnCount(); j++ )
            colWidth += tcm.getColumn( j ).getPreferredWidth();
        // Have to check scroll for width > 0, because the first time this gets
        // called, it is 0, and that will cause the viewport to scale to fit the
        // entire table (which could be bad).  Note that this will get updated
        // if the window is resized as well.
        if( _tableScroll.getWidth() > 0 && colWidth < _tableScroll.getWidth() )
            _table.setAutoResizeMode( JTable.AUTO_RESIZE_ALL_COLUMNS );
        else
            _table.setAutoResizeMode( JTable.AUTO_RESIZE_OFF );
    }What that does is whenever the table's parent component is resized it evaluates the pref width of the whole table, if it's greater than the scrollpane's width, it turns autosizing of columns off (which will make the horiz scrollbar work properly), if it is less than the scrollpane's width, it turns autosizing on. Hackish I know.
    You need to make sure to call the _parentResized() method as well whenver you do something else that might cause the pref width of the table to be resized (like you repopulate and calc pref widths, etc.)
    Hope this is of some use to you.

  • Updating a JTable by hiding/displaying columns

    I have a customizable JTable where I display/hide columns according to a users' selection criteria. My code works fine for hiding/displaying columns if the Jtable is opened for the fist time, but doesnot work if I want to hide columns in already displayed table.How do I do it?? Any clue?? I tried
    myTabModel.fireTableDataChanged();
    but this only works for updating the table data...it does not hide columns for me... when I hide column I just remove desired column like this:
    myTable.removeColumn(myTable.getColumn("Column 3"));

    Here is the sample code I tried. It worked without any invalidate or repaint or updateUI(). generated using NetBeans
    check for <==== for the line of code doing this
    * TableTest.java
    * Created on October 9, 2002, 1:42 PM
    * @author  Anki Reddy Nelaturu
    public class TableTest extends javax.swing.JFrame {
        /** Creates new form TableTest */
        public TableTest() {
            initComponents();
        /** This method is called from within the constructor to
         * initialize the form.
         * WARNING: Do NOT modify this code. The content of this method is
         * always regenerated by the Form Editor.
        private void initComponents() {
            jScrollPane1 = new javax.swing.JScrollPane();
            jTable1 = new javax.swing.JTable();
            jButton1 = new javax.swing.JButton();
            jTextField1 = new javax.swing.JTextField();
            menuBar = new javax.swing.JMenuBar();
            fileMenu = new javax.swing.JMenu();
            openMenuItem = new javax.swing.JMenuItem();
            saveMenuItem = new javax.swing.JMenuItem();
            saveAsMenuItem = new javax.swing.JMenuItem();
            exitMenuItem = new javax.swing.JMenuItem();
            editMenu = new javax.swing.JMenu();
            cutMenuItem = new javax.swing.JMenuItem();
            copyMenuItem = new javax.swing.JMenuItem();
            pasteMenuItem = new javax.swing.JMenuItem();
            deleteMenuItem = new javax.swing.JMenuItem();
            helpMenu = new javax.swing.JMenu();
            contentsMenuItem = new javax.swing.JMenuItem();
            aboutMenuItem = new javax.swing.JMenuItem();
            getContentPane().setLayout(null);
            addWindowListener(new java.awt.event.WindowAdapter() {
                public void windowClosing(java.awt.event.WindowEvent evt) {
                    exitForm(evt);
            jTable1.setModel(new javax.swing.table.DefaultTableModel(
                new Object [][] {
                    {null, null, null, null},
                    {null, null, null, null},
                    {null, null, null, null},
                    {null, null, null, null}
                new String [] {
                    "Title 1", "Title 2", "Title 3", "Title 4"
            jScrollPane1.setViewportView(jTable1);
            getContentPane().add(jScrollPane1);
            jScrollPane1.setBounds(80, 30, 230, 120);
            jButton1.setText("jButton1");
            jButton1.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    jButton1ActionPerformed(evt);
            getContentPane().add(jButton1);
            jButton1.setBounds(170, 180, 81, 26);
            jTextField1.setText("jTextField1");
            getContentPane().add(jTextField1);
            jTextField1.setBounds(60, 190, 63, 20);
            fileMenu.setText("File");
            openMenuItem.setText("Open");
            fileMenu.add(openMenuItem);
            saveMenuItem.setText("Save");
            fileMenu.add(saveMenuItem);
            saveAsMenuItem.setText("Save As ...");
            fileMenu.add(saveAsMenuItem);
            exitMenuItem.setText("Exit");
            exitMenuItem.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    exitMenuItemActionPerformed(evt);
            fileMenu.add(exitMenuItem);
            menuBar.add(fileMenu);
            editMenu.setText("Edit");
            cutMenuItem.setText("Cut");
            editMenu.add(cutMenuItem);
            copyMenuItem.setText("Copy");
            editMenu.add(copyMenuItem);
            pasteMenuItem.setText("Paste");
            editMenu.add(pasteMenuItem);
            deleteMenuItem.setText("Delete");
            editMenu.add(deleteMenuItem);
            menuBar.add(editMenu);
            helpMenu.setText("Help");
            contentsMenuItem.setText("Contents");
            helpMenu.add(contentsMenuItem);
            aboutMenuItem.setText("About");
            helpMenu.add(aboutMenuItem);
            menuBar.add(helpMenu);
            setJMenuBar(menuBar);
            pack();
        private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
            jTable1.removeColumn(jTable1.getColumnModel().getColumn(Integer.parseInt(jTextField1.getText())));        // <========
        private void exitMenuItemActionPerformed(java.awt.event.ActionEvent evt) {
            System.exit(0);
        /** Exit the Application */
        private void exitForm(java.awt.event.WindowEvent evt) {
            System.exit(0);
         * @param args the command line arguments
        public static void main(String args[]) {
            new TableTest().show();
        // Variables declaration - do not modify
        private javax.swing.JScrollPane jScrollPane1;
        private javax.swing.JMenu fileMenu;
        private javax.swing.JMenuItem exitMenuItem;
        private javax.swing.JButton jButton1;
        private javax.swing.JMenuItem saveAsMenuItem;
        private javax.swing.JMenuItem saveMenuItem;
        private javax.swing.JMenuItem copyMenuItem;
        private javax.swing.JMenuItem pasteMenuItem;
        private javax.swing.JMenuItem cutMenuItem;
        private javax.swing.JMenuItem openMenuItem;
        private javax.swing.JMenuBar menuBar;
        private javax.swing.JMenu editMenu;
        private javax.swing.JMenuItem aboutMenuItem;
        private javax.swing.JMenuItem contentsMenuItem;
        private javax.swing.JMenu helpMenu;
        private javax.swing.JTextField jTextField1;
        private javax.swing.JMenuItem deleteMenuItem;
        private javax.swing.JTable jTable1;
        // End of variables declaration
    }

  • 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

  • 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 paste a column of email addresses from an excel spreadsheet into a Mail message To: window

    In the past I have been able to send a group email by copying a column of email addresses from an Excel spreadsheet and pasting it into the To: window of an email message I had composed. I simply dragged my cursor down the column containing the email addresses, right-clicked Copy, put my cursor into the To: window of the email, and hit Paste. Mail recognized the list as a series of email addresses and I was able to hit Send and the email went on its way.
    Today I tried to do this and after I hit Send I got an error message. It appears to me that Mail did not recognize the list as a series of individual email addresses but saw them as one long address; the error message said it "did not appear to be a valid email address". Has something changed in Mail? I recently installed Mavericks!
    I can't be the only one who sends group emails this way. Are others experiencing this problem?

    Now Tony, I know you can't hear my tone on a forum post but I was not complaining, simply stating facts . This change brought several people in my office to a grinding halt in a long established workflow that is really rather simple (and I thought was already assumed from the original post above ):
    1) Select a set of records in FileMaker Pro 12 and export only their e-mail addresses as a CSV file.
    2) Open that CSV file in Excel.
    3) Copy the column of e-mail address.
    4) paste into the appropriate recipient field in Mail.
    5) Send
    If I were to complain it would be about Apple's typically opaque approach to updates. There is no granular explanation of why changes were made or even "what" changes were made.
    Complaining is futile since Apple is Apple and is unlikely to change, but sometimes it is cathartic to "shout into the void" .
    I had thought about doing something with a formula in Excel and your suggestion was simple and helpful. Again, however, it is only a workaround for a long established helpful behavior that Apple has inexplicably broken/removed in Mavericks Mail.
    I, and the other posters here, would love to have the capability back rather than have to add previously unneeded steps to our workflows.
    Ultimately we may add scripting steps to the FileMaker side to export the address lists with commas inserted already if Apple ends up having permanently removed this feature.

  • Hiding a column while keeping the data in the TableModel

    Hello
    I am reading data in from a database and I add the data from the resultSet to
    a vector of vectors.
    e.g my table
    user_id | user_fname | user_lname | prj_id | prj_name
    I am reading in the above information but I dont want to
    display the id fields i.e
    the user_id and
    the prj_id fields
    to the user but I need to keep them in the vector inside my tablemodel
    for futher database manipulation.
    I've looked at threads saying to set the width of the column to 0 is this the best way???
    Could someone please share with me a way to do the above.
    Thank you very much

    Figure out how to call the removeColumn method on your JTable. Calling the method only removes the column viewed (JTable), not the actual column in the (DefaultTable) Model.
    If you go for the proposed "do it so small it cant be seen" solution, you have to "lock" the colum width so users can't do it bigger manually with the mouse...

  • Hiding the column data. What is the point of DBMS_CRYPTO package?

    DB version:10g R2
    A requirement has come where we need to hide some columns' data from end users.
    Trasparent Data Encryption feature wouldn't do the trick as it encrypts the data only at the storage level not at user level.
    I've seen PL/SQL codes using DBMS_CRYPTO which encrypts and decrypts input strings like the code mentioned in
    Re: Need some hints on using dbms_crypto
    What is point of these PL/SQL codes?
    They can only be used to create functions which will be called in VIEWS. That is the only use of DBMS_CRYPTO package. Right?
    Do you guys have any suggestion in hiding/obfuscating column data? Is creating a view my only option?

    One solution to "hide" data (columns or rows) from end users is simply to create a view.
    The end user will be granted only access to the view and not to the base tables behind the view. The view will only expose those cloumns and rows that the end users is supposed to see.
    Of cause this has nothing to do with encryption. But I don't see anything in your business requirements that needs to use encryption methods.

  • Keyboard Access For a Column in JTable with default editor as JComboBox

    I want to get Key board access for a column in JTable.
    The user should be able to select from a drop down list for the column with default
    editor set as JComboBox.
    Presently,it works fine with mouse,also I am able to focus it with Keyboard using
    ALT+Up keys,but how to make drop down list appear.
    Plz help,it's urgent.
    Thanks in Advance

    Hi,
    In addition to setting DO_SUM = 'X' you need to specify function in H_FTYPE field. It should be set to 'AVG' in your case.
    ls_fielcat-do_sum = 'X'.
    ls_fieldcat-h_ftype = 'AVG.

  • Serial number column in Jtable

    Apologies for this distraction.
    I read at this forum about a year ago how to add a s/n column in Jtable such that all the nos are automatically updated/adjusted when a row is added/deleted. the count starts from the top down serially and unaffected by sorting.
    pls help!

    thanks a million BaltimoreJohn and especially camickr whose solutions to problems have been most helpful. applying the referenced post, i worked around the problem by resetting the values of the column having the serial number, based on table rowCount every time there is an operation on it(deleting, addition etc)

  • Reorder columns in JTable

    Hi.
    I want to reorder the columns in a JTable. I want the user to be free to resize and reorder the columns just as he wants, save it, and reuse these settings the next time. I have no problems getting the current configuration. But I cannot handle resetting these. What I tried is
    mytable.getColumnModel().getColumn(i).setModelIndex(newIndex);
    mytable.getColumnModel().getColumn(i).setWidth(newWidth);The data is reordered correctly. But the header is still the old one. And the width is also the old. What do I do wrong here?
    (I also thought about TableColumnModel.moveColumn(int,int), but I don't want to remember all movements, just the result...)
    Thx.
    Kay Dohmann

    ADF Swing's table binding doesn't support dynamically adjusting the column model automatically based on the hidden control hint.
    The ADF Swing design time does hide the hidden attributes to they don't show up in the generated panel/form.
    I'd recommend looking at the techniques illustrated in the ADF JClient Component Demo on this page full of demo code:
    http://www.oracle.com/technology/sample_code/products/jdev/index.html
    The readme file for that demo is here:
    http://www.oracle.com/technology/sample_code/products/jdev/1012/jclient_guide/adf_jclientcomponentdemo_readme.html
    The table demo has a checkbox that illustrates hiding a column as well as another that illustrates changing a column heading dynamically.

  • Trouble viewing column headers JTable

    I am having trouble with the column headers showing up. I have added a JScrollPane to the JTable, yet it fails to show up
    Here is the array for the data and column headings:
         String[] tableheadings = {"","Jan", "Feb", "Mar","Apr","Jun", "Jul"};
         Object data[] [] = { { "Rent","","","","","",""},
                             {"Utilities","","","","","",""},
                             {"Groceris","","","","","",""},
                             {"Clothes","","","","","",""},
                             {"Bills","","","","","",""},
                             {"Automobile","","","","","",""},
    and here is the method calling the array and placing into a JTable:
         public void doEside()
              east = new JPanel (new GridLayout(2,1));
              quote = new JLabel ("<HTML><FONT SIZE=+1><CENTER><B>\"Healthy</B>"
                   +"<BR>Wealthy</BR>"
                   +"<BR>and</BR>"
                   +"<BR>Wise\"</BR></CENTER></FONT>", JLabel.CENTER);
              table = new JTable(data, tableheadings);
              DefaultTableModel dmodel = new DefaultTableModel(data, tableheadings)
                   public boolean isCellEditable(int row,int column)
                        return false;
              table = new JTable(dmodel);
              table.setPreferredScrollableViewportSize(new Dimension( 200,70));
              table.getColumnModel().getColumn(0).setPreferredWidth(70);
              table.getColumnModel().getColumn(1).setPreferredWidth(10);
              table.getColumnModel().getColumn(2).setPreferredWidth(10);
              table.getColumnModel().getColumn(3).setPreferredWidth(10);
              table.getColumnModel().getColumn(4).setPreferredWidth(10);
              table.getColumnModel().getColumn(5).setPreferredWidth(10);
              table.getColumnModel().getColumn(6).setPreferredWidth(10);
              table.getTableHeader();
              JScrollPane sp = new JScrollPane(table);
              sp.add(table);
              east.add(quote);
              east.add(table);
              add(east, BorderLayout.EAST);
                   

    That's a Swing question, it should be asked in the Swing forum.
    A JTable always represents the values provided by a TableModel.
    The JTable constructor that directly takes the heading and data is just a convenience constructor which creates a DefaultTableModel and populates it using the supplied arguments.
    You code extract creates two JTable object. The first one (the one with the data and headings) is lost for good after you reassign the variable table to the second JTavble instance. And this second instance is created with an empty DefaultTableModel.
    What you want is probably to create one single JTAble object, using a model created as:
    dtmodel = new DefaultTableModel(data, tableheadings);Edited by: jduprez on Nov 19, 2009 1:18 PM

  • Scroll Fix Column in JTable

    I have see a lots of examples of whow to create fix column into JTable.
    But all the examples have the same problems.
    When I wont to scroll over the fix column the vertical scroll bar of the no fix column dont move, so the no fix column dose not move and the fix columns and no fix columns aren?t alined.
    If sameone have same example, send it please !!!!
    Thanks !!!
    Pablo

    In a recent project I've had the same problem.
    After a long research at the Swing forum at java.sun.org and google I found out that
    1. Currently there is no proper Open Source solution
    2. All the postings at sun are good concepts, but far away from solutions
    3. The only (for me )acceptable commercial solution is the JCTable from Quest (formerly KGroup)
    Since I want to have full control over the source code of the table, I decided to collect all the tips from this forums and write my own table.
    Here is a first try:
    http://jroller.com/resources/kriede/CoolTable.java
    The main idea is to have two tables, one for the locked columns (= fixed columns = frozen columns) and one for the scrollable columns. With all the tips from this forum it was more or less a puzzle to make it work pretty.

  • Need to Convert Comma separated data in a column into individual rows from

    Hi,
    I need to Convert Comma separated data in a column into individual rows from a table.
    Eg: JOB1 SMITH,ALLEN,WARD,JONES
    OUTPUT required ;-
    JOB1 SMITH
    JOB1 ALLEN
    JOB1 WARD
    JOB1 JONES
    Got a solution using Oracle provided regexp_substr function, which comes handy for this scenario.
    But I need to use a database independent solution
    Thanks in advance for your valuable inputs.
    George

    Go for ETL solution. There are couple of ways to implement.
    If helps mark

Maybe you are looking for

  • Macbook pro slow finder apps not working many errors found in console

    Problem description: finder is slow very at startup many errors found in console and after fixing some show up again and when fixed others show up. I run etrecheck here is the report. Thank you for any help EtreCheck version: 2.0.4 (89) Report genera

  • Problems with outlook

    outlook does not have a print icon on the email page like messenger did, when printing received emails it prints sidebars top bars and not the whole message I get it to print by clicking on ctrl p Help I only want the print the received e-mail

  • What exactly does accounts in restrictions do?

    As far as the ipod touch manual has mentioned (yes the latest), accounts in restrictions only blocks changes, additions and subtractions to the calendar, contacts and mail. But some of my friends have said that it also stops you from activating and l

  • Firefox doesn't detect that an update is available.

    On a particular PC I am using (Windows 7), I have Firefox 34.0 installed. The About Mozilla Firefox dialog shows that I have version "34.0" installed, and indicates that "Firefox is up to date." However, on another PC, also running Windows 7, I have

  • Best practice Eloqua Landing Page examples

    Hi I was just wondering if anybody had any examples they have found of Landing Pages created in Eloqua that they think have been done excellently done. I feel like I have improved mine significantly since I started working at my current company, howe