Column Hide in JTable

Hi There,
We are using Jtable to show data using DefaultTableModel. Now we have to implement some hidden columns in this existing JTable.
For this we have tried many ways but not succeeded.
1. We have use width=0 and setting header caption ="" but it shows column with some width insteed of being hidden.
2. further we tried dtm.setColumnCount(numCols) to set required number of columns to be displayed and it does so but ignore the rest columns. So this way is not useful as well.
Please suggest us how to implement hidden columns in JTable ?
Thanx in Adv,

I would strongly recommend that you use JXTable instead from the SwingX project. It even has a simple Popup Column Control that helps you hide and show columns as desired. But here is some simple code that might be useful
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.Enumeration;
import java.util.Vector;
import javax.swing.JTable;
import javax.swing.table.DefaultTableColumnModel;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.JTableHeader;
import javax.swing.table.TableCellRenderer;
import javax.swing.table.TableColumn;
import javax.swing.table.TableModel;
public class TableUtilities {
     * Restores a hidden TableColumn based on the supplied column index and sets to column
     * width to the supplied preferredWidth
     * @param table
     * @param modelIndex
     * @param columnWidth
    public static void restoreColumn(JTable table, int modelIndex, int columnWidth) {
        if (table.getColumnCount() <= 0) {
            return;
        TableColumn column = new TableColumn(modelIndex);
        column.setHeaderValue(table.getModel().getColumnName(modelIndex));
        column.setCellRenderer(table.getCellRenderer(0, modelIndex));
        column.setCellEditor(table.getCellEditor(0, modelIndex));
        column.setPreferredWidth(columnWidth);
        DefaultTableColumnModel model = (DefaultTableColumnModel) table.getColumnModel();
        model.addColumn(column);
        model.moveColumn(model.getColumnCount() - 1, modelIndex);
     * Restores a hidden TableColumn based on the supplied column index.
     * @param table
     * @param modelIndex
    public static void restoreColumn(JTable table, int modelIndex) {
        TableColumn column = new TableColumn(modelIndex);
        column.setHeaderValue(table.getModel().getColumnName(modelIndex));
        column.setCellRenderer(table.getCellRenderer(0, modelIndex));
        column.setCellEditor(table.getCellEditor(0, modelIndex));
        column.setPreferredWidth(120);
        DefaultTableColumnModel model = (DefaultTableColumnModel) table.getColumnModel();
        model.addColumn(column);
        model.moveColumn(model.getColumnCount() - 1, modelIndex);
     * Restores a hidden TableColumn based on the supplied column name.
     * @param table
     * @param column
    public static void restoreColumn(JTable table, String column) {
        restoreColumn(table, getColumnIndex(table.getModel(), column));
     * Restores a hidden TableColumn based on the supplied column name and sets to column
     * width to the supplied preferredWidth
     * @param table
     * @param columnWidth
     * @param column
    public static void restoreColumn(JTable table, String column, int columnWidth) {
        restoreColumn(table, getColumnIndex(table.getModel(), column), columnWidth);
     * Carries out the process to hide a table column from the view based on the supplied
     * column name
     * @param table
     * @param column
    public static void hideColumn(JTable table, String column) {
        hideColumn(table, table.convertColumnIndexToView(getColumnIndex(table.getModel(), column)));
     * Carries out the process to hide a table column from the view based on the supplied
     * column index
     * @param table
     * @param column
    public static void hideColumn(JTable table, int column) {
        DefaultTableColumnModel model = (DefaultTableColumnModel) table.getColumnModel();
        if (model.getColumnCount() != 0 && column != -1) {
            model.removeColumn(model.getColumn(column));
     * Returns a Vector of Strings containing the columnNames of for the specified TableModel
     * @param model
     * @return
    public static Vector<String> getColumnNames(TableModel model) {
        Vector<String> colNames = new Vector<String>();
        for (int i = 0; i < model.getColumnCount(); i++) {
            colNames.add(model.getColumnName(i));
        return colNames;
     * Returns the first index of the column with the specified name in the supplied TableModel.
     * @param model
     * @param name
     * @return
    public static int getColumnIndex(TableModel model, String name) {
        for (int i = 0; i < model.getColumnCount(); i++) {
            if (model.getColumnName(i).equalsIgnoreCase(name)) {
                return i;
        return -1;
}ICE
Edited by: fadugyamfi on Aug 17, 2009 11:05 AM

Similar Messages

  • Hide a column in a JTable

    Hi All, hope you can help,
    I want to hide the last column of my table, but still access its data. Inside the last column certain information is present, the cell tooltips.
    In my extended JTable class my method getToolTipText looks like this:
            // implement table cell tool tip.
            public String getToolTipText(MouseEvent e) {
                String tip             = null;
                Point  p               = e.getPoint();
                int    rowIndex        = rowAtPoint(p);
                int    colIndex        = columnAtPoint(p);
                int    realColumnIndex = convertColumnIndexToModel(colIndex);
                if(rowIndex>=0 && rowIndex<=lastRow) {
                    if(realColumnIndex==0) {
                        MiniModel mml = (MiniModel)getValueAt(rowIndex, 5); // exception here
                        tip = "<html>" + replaceCRLFtoBR(mml.getComment()) + "</html>"; // replaceCRLFtoBR = custom method to replace \n by <br>
                    } else {
                        tip = columnTips[realColumnIndex]; // constant
                return tip;
            }As you can see at column 5 an object MiniModel is present containing the tooltip for column 0.
    When I use the method removeColumn on column 5 on my extended JTable variable, I get an java.lang.ArrayIndexOutOfBoundsException at the marked position and in more detail on getValueAt.
    As I read everywhere the actual data is not removed (only from the view) I wonder what I'm doing wrong...
    Michiel

    Thanks for the advice, I will prepare better next time, here is my sscce :
    import java.awt.BorderLayout;
    import java.awt.Dimension;
    import java.awt.Point;
    import java.awt.event.MouseEvent;
    import javax.swing.JFrame;
    import javax.swing.JScrollPane;
    import javax.swing.JTable;
    import javax.swing.ListSelectionModel;
    import javax.swing.UIManager;
    import javax.swing.table.DefaultTableModel;
    import javax.swing.table.JTableHeader;
    public class TableHide extends JFrame {
        private static final String[] colNames    = {"Column 1", "Column 2", "Column 3"};
        private static final String[] colHeadTips = {"Header tip 1", "Header tip 2", "Header tip 3"};
        private ExtTableModel    myTableModel;
        private ExtTable         myTable;
        private JScrollPane      myScrollPane;
        private int              lastRow = 0;
        // for example
        private MiniModel mmlRow1 = new MiniModel(1, "cell comment");
        private MiniModel mmlRow2 = new MiniModel(2, "other cell comment");
        // constructor
        public TableHide() {
            this.setTitle("Table column hide test");
            this.setResizable(true);
            this.setLayout(new BorderLayout());
            // build table containing all extended Model's id and name
            myTableModel = new ExtTableModel(null, colNames);
            myTable      = new ExtTable(myTableModel);
            myTable.setAutoResizeMode(JTable.AUTO_RESIZE_SUBSEQUENT_COLUMNS);
            myTable.setPreferredScrollableViewportSize(new Dimension(500, 130));
            myTable.setFillsViewportHeight(true);
            myTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
            myTable.getTableHeader().setReorderingAllowed(false);
            myScrollPane = new JScrollPane(myTable);
            this.add(myScrollPane, BorderLayout.CENTER);
            // add some rows, in real application this is more complex
            myTableModel.insertRow(0, new Object[]{ "Basic string", new Boolean(false), mmlRow1 }); lastRow++;
            myTableModel.insertRow(0, new Object[]{ "Other string", new Boolean(true) , mmlRow2 }); lastRow++;
            myTable.setAutoCreateRowSorter(true);
            myTable.getRowSorter().toggleSortOrder(0);
            // this causes the exception
            myTable.removeColumn(myTable.getColumnModel().getColumn(2));
            this.setSize(new Dimension(500,200));
        // inner class to provide an own table model for the extended Models showed on screen. used for booleans
        class ExtTableModel extends DefaultTableModel {
            public ExtTableModel(Object[][] tableData, String[] columnNames) {
                super(tableData, columnNames);
            public boolean isCellEditable(int row, int col) {
                return false;
            public Class getColumnClass(int column){
                Object value=this.getValueAt(0,column);
                return (value==null?Object.class:value.getClass());
        // inner class to privide column header tooltips and cell tooltips
        class ExtTable extends JTable {
            public ExtTable(ExtTableModel extModel) {
                super(extModel);
            // implement table cell tool tip.
            public String getToolTipText(MouseEvent e) {
                String tip             = null;
                Point  p               = e.getPoint();
                int    rowIndex        = rowAtPoint(p);
                int    colIndex        = columnAtPoint(p);
                int    realColumnIndex = convertColumnIndexToModel(colIndex);
                if(rowIndex>=0 && rowIndex<=lastRow) {
                    if(realColumnIndex==0) {
                        MiniModel mml = (MiniModel)getValueAt(rowIndex, 2);
                        tip = mml.getMml_comment();
                    } else {
                        tip = "Some other tooltip function";
                return tip;
            // implement table header tool tip.
            protected JTableHeader createDefaultTableHeader() {
                return new JTableHeader(columnModel) {
                    public String getToolTipText(MouseEvent e) {
                        Point  p         = e.getPoint();
                        int    index     = columnModel.getColumnIndexAtX(p.x);
                        int    realIndex = columnModel.getColumn(index).getModelIndex();
                        return colHeadTips[realIndex];
        // simplified class for usage inside a cell
        public class MiniModel {
            private int        mml_id;
            private String     mml_comment;
            public MiniModel(int mml_id, String mml_comment) {
                this.mml_id      = mml_id;
                this.mml_comment = mml_comment;
            public String getMml_comment() {
                return mml_comment;
            public String toString() {
                return Integer.toString(mml_id); // called when object is displayed
        public static void main(String[] args) {
            java.awt.EventQueue.invokeLater(new Runnable() {
                public void run() {
                    try { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
                    } catch (Exception ex) {
                        ex.printStackTrace();
                    new TableHide().setVisible(true);
    }When you show the last column the program works fine. Goal is to have the last column available since it contains extra information about the row, but not to show it.

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

  • How can I add custom right-click-menu to column headers in JTable?

    Can anyone point me to a topic on how to customize a popup menu for column headers in JTable? Specifically, I want to add things like "auto-size column" and "hide column".
    Thanks,
    Matt

    Right-click on your table.  Then go to Advanced->Runtime Shortcut Menu->Edit.
    There are only two ways to tell somebody thanks: Kudos and Marked Solutions
    Unofficial Forum Rules and Guidelines

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

  • Hiding columns of a JTable

    I want to hide some of the columns of my JTable. Plz tell me how to do it?
    Thanks in advance

    Alternatively, remove those columns from the table's columnModel.Definitely the preferred approach.
    Wouldn't you still have to modify the TableModel so that the getValueAt method doesn't return the wrong value?No, the view of the table is not necessarily the same as the order of the data in the TableModel. What happens, for example when a column of the table is reordered? Well, each TableColumn contains a reference to a specific column in the TableModel. So the TableColumnModel is used by the table to control the view of the table and the TableColumn will get the data from the correct column. This way you can reorder TableColumns or remove TableColumns withouth affecting the TableModel only the view of the table.
    My FixedColumnScrollPane example uses this feature:
    http://forum.java.sun.com/thread.jspa?forumID=257&threadID=500055
    By the way, when you use the getValueAt(...) method you have to be carefull which index you use for the column.
    a) Do you want the first column viewable in the table, then just use the column
    b) Do you want the first column from the TableModel. In this case you have some helper methods (in case columns have been reordered or removed):
    convertColumnIndexToModel()
    convertColumnIndexToView()

  • How to get all the values in one column of a JTable

    How to get all the values in one column of a JTable as a Collection of String.
    I don;t want to write a for loop to say getValueAt(row, 1) eg for 2nd column.

    I don;t want to write a for loop to say getValueAt(row, 1) eg for 2nd column. You could always write a custom TableModel that stores the data in the format you want it. It would probably be about 50 lines of code. Or you could write a loop in 3 lines of code. I'll let you decide which approach you want to take.

  • How to create Hyperlink column in a JTable

    Can anyone help in creating a hyperlink column in a JTable.
    Thanks in advance,
    Sridhar.

    If the parent is an Applet it is very simple .
    catch the mouse click on columns and execute the following code
    String url = getValueAt(i,j);
    getAppletContext().showDocument(new
    URL(url ), "_blank");
    thatz all .
    if ur program is an application use this getRuntime.exec() and use parameters to rundll32.exe url and iexplore.exe in Windows platform,
    if u have still doubts plz get back to me
    Renjith K.V

  • How to fix the value of first column in the JTable in java swing for every

    Hi ,
    I have a swing page that have table panel in which there is a table of size 7x4 now when I click on the perticulat row then that row data will displayin the table like that the selected row become the second column in the new table and the fist column of this table will remain constant for all the entry but the second column update according to the roe which is selected .How it is possible .
    Thanks in Advace,
    anu

    One thing you can do is to prevent the user from editing that column and programatically supply the values of that column yourself.
    JTable table = new JTable() {
       public boolean isCellEditable(int row, int col) {
           if(col == 0) {
              return false;
           return super.isCellEditable(row, col);
    };This allows you to prevent the user from editing the column information so you can supply some sort of a default value for the column always
    ICE

  • Looking for component: flexible rows like columns in a JTable

    Hello,
    I need a swing component to display several rows which can be moved up and down, the height resized, interchanged with the mouse like the columns in a JTable. But there is no need for columns. I think there is no standard swing component.
    Any ideas, resource hints?
    Thanks, Ulrich

    One more piece of advice. It is not very easy to get "pre-written custom components". Most developers do things to meet their own needs and these may not be exactly what you are looking for. The best thing to do is to try to develop this yourself. It will give you loads of experience and in later programmes you may write, based on the experience you obtained from the "pain-staking" development process you'll know how to go round these problems quicker and may be able to help others also.
    So just start writing some stuff. You may end up finishing sooner than you think. And remember forum members are always ready to help with problems (accompanied by minimal code examples of the actual problem).
    ICE

  • Help for adjusting columns of a JTAble in a Table Model

    Hello community,
    In order to have a good display of by DataBase in a JTable, I've wrote some code to adjust columns in function of datas. Those datas are displayed with a TableModel ( which I've declared in a class JDBCAdapter ).
    When I start my application, I call adjustColumns(), and all is great but when I add information to my DB and display it, the columns of my JTable return to default width...
    So I want to incorporate my function adjustColumns in my TableModel, and I need help...
         void adjustColumns()
         // Ajuste les colonnes aux donnes pour que tout soit visible
         int nbRow,nbCol;
         nbRow = JTable1.getRowCount();
         nbCol = test.getColumnCount();
         for ( int i = 0; i < nbCol; i++ )
         com.sun.java.swing.table.TableColumn column = null;
         column = JTable1.getColumnModel().getColumn(i);
         int dataLength = 0;
         for ( int j = 0; j< nbRow; j++ )
         FontMetrics fm;
         int dataLengthTmp;
         String valueTable;
         fm = JTable1.getFontMetrics(JTable1.getFont());
         if ( test.getValueAt(j, i) == null )
         System.out.println("Valeur nulle...");
         dataLengthTmp = 0;
         else
         valueTable = test.getValueAt(j, i).toString();
         dataLengthTmp = fm.stringWidth(valueTable);
         System.out.println(valueTable + " = " + dataLengthTmp);
         if ( dataLengthTmp > dataLength )
         dataLength = dataLengthTmp;
         if ( dataLength != 0 )
    column.setWidth(dataLength + 5);
    else
    column.sizeWidthToFit();
    JTable1.setModel(test);
    JTable1.repaint();
    import java.util.Vector;
    import java.sql.*;
    import com.sun.java.swing.table.AbstractTableModel;
    import com.sun.java.swing.event.TableModelEvent;
    public class JDBCAdapter extends AbstractTableModel {
    Connection connection;
    Statement statement;
    ResultSet resultSet;
    String[] columnNames = {};
    Vector rows = new Vector();
    ResultSetMetaData metaData;
    public JDBCAdapter(String url, String driverName,
    String user, String passwd) {
    try {
    Class.forName(driverName);
    System.out.println("Ouverture de la connexion a la base de donnee...");
    connection = DriverManager.getConnection(url, user, passwd);
    statement = connection.createStatement();
    catch (ClassNotFoundException ex) {
    System.err.println("Cannot find the database driver classes.");
    System.err.println(ex);
    catch (SQLException ex) {
    System.err.println("Cannot connect to this database.");
    System.err.println(ex);
    public void executeQuery(String query) {
    if (connection == null || statement == null) {
    System.err.println("There is no database to execute the query.");
    return;
    try {
    resultSet = statement.executeQuery(query);
    metaData = resultSet.getMetaData();
    int numberOfColumns = metaData.getColumnCount();
    columnNames = new String[numberOfColumns];
    // Get the column names and cache them.
    // Then we can close the connection.
    for(int column = 0; column < numberOfColumns; column++) {
    columnNames[column] = metaData.getColumnLabel(column+1);
    // Get all rows.
    rows = new Vector();
    while (resultSet.next()) {
    Vector newRow = new Vector();
    for (int i = 1; i <= getColumnCount(); i++) {
    newRow.addElement(resultSet.getObject(i));
    rows.addElement(newRow);
    // close(); Need to copy the metaData, bug in jdbc:odbc driver.
    fireTableChanged(null); // Tell the listeners a new table has arrived.
    catch (SQLException ex) {
    System.err.println(ex+" query = "+query);
    public void executeUpdate(String query) {
    if (connection == null || statement == null) {
    System.err.println("There is no database to execute the query.");
    return;
    try {
    statement.executeUpdate(query);
    // close(); Need to copy the metaData, bug in jdbc:odbc driver.
    fireTableChanged(null); // Tell the listeners a new table has arrived.
    catch (SQLException ex) {
    System.err.println(ex+" query = "+query);
    public void close() throws SQLException {
    System.out.println("Fermeture de la connection a la base de donnee... Bye !");
    resultSet.close();
    statement.close();
    connection.close();
    protected void finalize() throws Throwable {
    close();
    super.finalize();
    // Implementation of the TableModel Interface
    // MetaData
    public String getColumnName(int column) {
    if (columnNames[column] != null) {
    return columnNames[column];
    } else {
    return "";
    public Class getColumnClass(int column) {
    int type;
    try {
    type = metaData.getColumnType(column+1);
    catch (SQLException e) {
    return super.getColumnClass(column);
    switch(type) {
    case Types.CHAR:
    case Types.VARCHAR:
    case Types.LONGVARCHAR:
    return String.class;
    case Types.BIT:
    return Boolean.class;
    case Types.TINYINT:
    case Types.SMALLINT:
    case Types.INTEGER:
    return Integer.class;
    case Types.BIGINT:
    return Long.class;
    case Types.FLOAT:
    case Types.DOUBLE:
    return Double.class;
    case Types.DATE:
    return java.sql.Date.class;
    default:
    return Object.class;
    public boolean isCellEditable(int row, int column) {
    try {
    return metaData.isWritable(column+1);
    catch (SQLException e) {
    return false;
    public int getColumnCount() {
    return columnNames.length;
    // Data methods
    public int getRowCount() {
    return rows.size();
    public Object getValueAt(int aRow, int aColumn) {
    Vector row = (Vector)rows.elementAt(aRow);
    return row.elementAt(aColumn);
    public String dbRepresentation(int column, Object value) {
    int type;
    if (value == null) {
    return "null";
    try {
    type = metaData.getColumnType(column+1);
    catch (SQLException e) {
    return value.toString();
    switch(type) {
    case Types.INTEGER:
    case Types.DOUBLE:
    case Types.FLOAT:
    return value.toString();
    case Types.BIT:
    return ((Boolean)value).booleanValue() ? "1" : "0";
    case Types.DATE:
    return value.toString(); // This will need some conversion.
    default:
    return "\""+value.toString()+"\"";
    public void setValueAt(Object value, int row, int column) {
    try {
    String tableName = metaData.getTableName(column+1);
    // Some of the drivers seem buggy, tableName should not be null.
    if (tableName == null) {
    System.out.println("Table name returned null.");
    String columnName = getColumnName(column);
    String query =
    "update "+tableName+
    " set "+columnName+" = "+dbRepresentation(column, value)+
    " where ";
    // We don't have a model of the schema so we don't know the
    // primary keys or which columns to lock on. To demonstrate
    // that editing is possible, we'll just lock on everything.
    for(int col = 0; col<getColumnCount(); col++) {
    String colName = getColumnName(col);
    if (colName.equals("")) {
    continue;
    if (col != 0) {
    query = query + " and ";
    query = query + colName +" = "+
    dbRepresentation(col, getValueAt(row, col));
    System.out.println(query);
    System.out.println("Not sending update to database");
    // statement.executeQuery(query);
    catch (SQLException e) {
    // e.printStackTrace();
    System.err.println("Update failed");
    Vector dataRow = (Vector)rows.elementAt(row);
    dataRow.setElementAt(value, column);
    Thanks to help me.

    Hi,
    OK. I have read your code sample again. It looks like the JDBCAdapter class is reloading table data in the executeQuery method. Why not call adjustColumns at the end of this method after the new rows and columns are loaded? Perhaps it also should be called at the end of executeUpdate. Have you tried doing that?
    I would still set
    JTable1.setAutoCreateColumnsFromModel (false); to prevent Java from readjusting the size automatically at some other time.
    regards,
    Terry

  • How to set a JRadioButton as a column in a JTable

    Hello Friends,
    I need a help in JTable.
    I want to have a Radio button as a column of a JTable.(The Other Columns should be Strings).
    The heading of the Column which has the RadioButton is "Select" which means that I can select only one radiobutton at a time.
    Could you please give me a solution on this.
    I would appreciate if u give me the code for this, as it is very urgent.
    Thanks in Advance,
    Regards,
    Vijayakannan

    Hi,
    use a TableCellRenderer and CellEditor as described in http://java.sun.com/docs/books/tutorial/uiswing/components/table.html
    Propably you need to track the selected button yourself, e.g. by using an int value representing the row selected.

  • Right Justify a column in a JTable

    Hello,
    I formatted a decimal number and want to put it into a column in a JTable. Unfortunately, the value is being left justified. How do I make the data for the column right justitified?

    Thank you both for your answers. I had looked in the tutorial, but could not find the area for justifications. I did have a table model with a getColumnClass too, but didnt realize that I didnt have to use the actual data type's class to render the justification.
    Looking back at the tutorial, I now find that ImageIcon is supposed to be used for centering, but this didnt work. It wiped out the data for the column I tried to use it on rather than justifying it left or right. Any ideas how to get centering to work?

  • Adding mouse listener to the column header of a column in a JTable

    Hi
    I want to add a mouse listener to the column header of the 3rd column in a JTable. I dont find any appropriate method to do this. The code I have written to do this is below. But on using this code, the mouselistener is invoked if I click on any column header. Can anyone please help me to fix this.
    table.getTableHeader().addMouseListener(new MouseAdapter() {
    public void mouseClicked(MouseEvent e) {
    /* some actions */
    }

          table.getTableHeader().addMouseListener(new MouseAdapter(){
               public void mousePressed(MouseEvent me) {
                   int tableColumn  =table.columnAtPoint(me.getPoint());//it returns the column index
            });

  • How to programmatically select a column in a JTable

    Hi,
    I'm writing a program which requires me to select a column in the JTable through code. The problem is that I could only find getSelectedColumn() function in JTable and no setSelectedColumn().
    Please let me know if there is any workaround for this.
    Regards,
    Derreck

    Hi,
    table.setColumnselectionInterval(index0,index1);
    The above line will suffice your requirement.
    Cheers,
    Gokul.

Maybe you are looking for

  • Noticed a small nick on my new X1 Carbon Touch Screen

    There is a small nick / deep scratch on the Protective screen protector.   Lenovo says this isn't covered under warranty.  Should I return to seller?  Or should I remove the screen protector?  It's like a small cut on the screen protector right in th

  • Check payment house bank

    User has done the payment sbi bank while updtion fch5 user has mistake  update with wrong house bank id and account id.How to control other house bank for particular bank in fchi please help me on this

  • Add field in standard ALV report.

    Hi friends, In SAP standard ALV report, t.code- S_ALR_87012050, user wants the vendor to include information about source document - vendor number, vendor name, invoice number, original document number of the transaction in the case of payroll being

  • Help needed with xml list

    hi, i need to make a list in which all the list items will come from xml file. these items will also be clickable so that they open a new respective hyperlink on click. i need something like www.sponky.com ' s portfolio list. can somebody please help

  • I cant to skype on my laptop anymore

    i cant to skype on my laptop anymore