src/main/java/org/jwellman/swing/jtable/TableColumnManager.java
private void showPopup(int index) {
        final JPopupMenu popup = new SelectPopupMenu();

        // Create a JCheckBoxMenuItem for all columns managed by the table column
        // manager, checking to see if the column is shown or hidden.
        final int columnCount = tableColumnModel.getColumnCount();
        final Object headerValue = tableColumnModel.getColumn(index).getHeaderValue();
        for (TableColumn tableColumn : allColumns) {
            
        	final Object value = tableColumn.getHeaderValue();
            final JCheckBoxMenuItem chkbox = new JCheckBoxMenuItem(value.toString());
            chkbox.addActionListener(this);
            chkbox.setSelected(false); // only set to true if it is visible; checked next
            popup.add(chkbox);

            try {
            	// This is how we check for visibility; will throw exception if not visible (i.e. missing)
                tableColumnModel.getColumnIndex(value);

                // Since an exception was not thrown, we know it is visible
                chkbox.setSelected(true);

                // If this is the last visible column, do not allow to be hidden by disabling checkbox
                if (columnCount == 1) chkbox.setEnabled(false); 

            } catch (IllegalArgumentException e) {
            	// This happens when the column is hidden
            }

            // Visually select the item corresponding to the right-clicked column
            if (value == headerValue) popup.setSelected(chkbox);
            
        }

        // Display the popup below the TableHeader
        final JTableHeader header = table.getTableHeader();
        final Rectangle r = header.getHeaderRect(index);
        popup.show(header, r.x, r.height);
    }
/*
     * Show a popup containing items for all the columns found in the table column
     * manager. The popup will be displayed below the table header columns that was
     * clicked.
     *
     * @param index index of the table header column that was clicked
     */
Show a popup containing items for all the columns found in the table column
manager. The popup will be displayed below the table header columns that was
clicked.

@param index index of the table header column that was clicked
Show a popup containing items for all the columns found in the table column manager . The popup will be displayed below the table header columns that was clicked . @param index index of the table header column that was clicked
private void showPopup(int index) {
        final JPopupMenu popup = new SelectPopupMenu();
        final int columnCount = tableColumnModel.getColumnCount();
        final Object headerValue = tableColumnModel.getColumn(index).getHeaderValue();
        for (TableColumn tableColumn : allColumns) {
        	final Object value = tableColumn.getHeaderValue();
            final JCheckBoxMenuItem chkbox = new JCheckBoxMenuItem(value.toString());
            chkbox.addActionListener(this);
            chkbox.setSelected(false); 
            popup.add(chkbox);
            try {
                tableColumnModel.getColumnIndex(value);
                chkbox.setSelected(true);
                if (columnCount == 1) chkbox.setEnabled(false); 
            } catch (IllegalArgumentException e) {
            }
            if (value == headerValue) popup.setSelected(chkbox);
        }
        final JTableHeader header = table.getTableHeader();
        final Rectangle r = header.getHeaderRect(index);
        popup.show(header, r.x, r.height);
    }
private void showPopup ( int index ) { final JPopupMenu popup = new SelectPopupMenu ( ) ; final int columnCount = tableColumnModel . getColumnCount ( ) ; final Object headerValue = tableColumnModel . getColumn ( index ) . getHeaderValue ( ) ; for ( TableColumn tableColumn : allColumns ) { final Object value = tableColumn . getHeaderValue ( ) ; final JCheckBoxMenuItem chkbox = new JCheckBoxMenuItem ( value . toString ( ) ) ; chkbox . addActionListener ( this ) ; chkbox . setSelected ( false ) ; popup . add ( chkbox ) ; try { tableColumnModel . getColumnIndex ( value ) ; chkbox . setSelected ( true ) ; if ( columnCount == 1 ) chkbox . setEnabled ( false ) ; } catch ( IllegalArgumentException e ) { } if ( value == headerValue ) popup . setSelected ( chkbox ) ; } final JTableHeader header = table . getTableHeader ( ) ; final Rectangle r = header . getHeaderRect ( index ) ; popup . show ( header , r . x , r . height ) ; }
Show a popup containing items for all the columns found in the table column
 manager.
Show a popup containing items for all the columns found in the table column manager .
// Create a JCheckBoxMenuItem for all columns managed by the table column // manager, checking to see if the column is shown or hidden. // only set to true if it is visible; checked next // This is how we check for visibility; will throw exception if not visible (i.e. missing) // Since an exception was not thrown, we know it is visible // If this is the last visible column, do not allow to be hidden by disabling checkbox // This happens when the column is hidden // Visually select the item corresponding to the right-clicked column // Display the popup below the TableHeader