Event for JTable column move

Can someone tell me which event is fired when a column is moved (dragging from one location to the next) in a JTable. I need to know when the move ends.
Thanks

RTM javax.swing.event.TableColumnModelEvent

Similar Messages

  • JTable - column move and column spacing

    Hi,
    Can someone please show me how to prevent users from being able to move columns. I am not finding any code to do this.
    Also, how do I set fixed width for columns. I am using vectors to populate the data
    Much appreciated

    Hi,
    This is a beginner level question and you should have been able to figure this out yourself.
    Have an array with size equal to the number of columns you have and store in each element of the array the size you want for the column. Then your code should be easy.
    // For a table with 4 columns
    double [] columnWidths = { 100.0, 109.0, 120.0, 95.0 };
    TableColumnModel columnModel = jTable.getColumnModel();
                   for ( int k = 0, count = columnModel.getColumnCount(); k < count; k++ ) {
                       TableColumn column = columnModel.getColumn( k );
                       // Do you mean this?
                      column.setResizable( true );
                       // or this ?
                                                                                   column.setMinWidth( columnWidths[k] );
                       column.setMaxWidth( columnWidths[k] );
                   cheers,
    vidyut
    http://www.bonanzasoft.com

  • Click event for single column in DataGrid

    I can add an event listener to a DataGrid of type
    ListEvent.ITEM_CLICK, which is triggered when the user clicks any
    part of an entire row in a DataGrid. I want to trigger a click
    event for just one column. I only want to run a function when the
    user clicks in just the first column of the DataGrid, and not run
    trigger the event if they click in any other column. Any help would
    be much appreciated.

    Accessing the event.target returns the entire DataGrid, not
    the DataGridColum. Any way to get just the DataGrid column?

  • JTable column movement and scroll bar

    Hello:
    I have a JTable with about 30-40 columns. Sometimes I would like to drag the column from rightmost to closer to the left end. I am not able to do that in one shot. and instead have to do it in multiple steps. Is there a way for the scroll bar to sort of move alongside the column as I drag it along?

    i dont know if there is way off hand. But you can put your own mouseListener of the JScrollPane and i am sure there is some method to check if you are dragging the JTable and if you are move the JScrollBar in the direction.
    I think that you are going to have to make you own implementation of this.
    David

  • Double click event for JTable.....

    All,
    I would like to display some data on double_click a selected row from the JTable. How do I code the double_click event in the following program. Please advise.
    Here is the code:
    import javax.swing.*;
    import javax.swing.table.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.util.Vector;
    class TableTest extends JFrame {
    MyTableModel myModel;
    JTable table;
    JButton button;
    JButton buttonQuery;
    int count = 0;
    public TableTest() {
    myModel = new MyTableModel();
    table = new JTable(myModel);
    table.setPreferredScrollableViewportSize(new Dimension(500, 200));
    JScrollPane scrollPane = new JScrollPane(table);
    //Add the scroll pane to this window.
    getContentPane().add(scrollPane, BorderLayout.CENTER);
    getContentPane().add(button = new JButton("Add Row"),
    BorderLayout.SOUTH);
    getContentPane().add(buttonQuery = new JButton("Query"), BorderLayout.NORTH);
    button.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent e) {
    Object [] aRow = new Object [8];
    for (int i=0; i<5; i++) {
    aRow = new Integer(count+i);
    myModel.addRow(aRow);
    count += 10;
    buttonQuery.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent e) {
    System.out.println(myModel.getRowCount());
    System.out.println(myModel.getValueAt(1, 3));
    addWindowListener(new WindowAdapter() {
    public void windowClosing(WindowEvent e) {
    System.exit(0);
    class MyTableModel extends AbstractTableModel {
    protected final String[] headers =
    { "No", "Vehicle No", "Date of Loss", "Image Type", "Image Description", "Claim Type", "Scan Date", "User Id" };
    Vector data;
    MyTableModel() {
    data = new Vector();
    public int getColumnCount() {
    return headers.length;
    public int getRowCount() {
    return data.size();
    public Object getValueAt(int row, int col) {
    if (row < data.size() && col < 8) {
    Object [] aRow = (Object []) data.elementAt(row);
    return aRow[col];
    } else {
    return null;
    public void addRow(Object [] aRow) {
    data.addElement(aRow);
    fireTableRowsInserted(data.size()-1, data.size()-1);
    public static void main(String[] args) {
    TableTest frame = new TableTest();
    frame.pack();
    frame.setVisible(true);
    }

    Thanks, but I get 1 error:
    'Cannot resolve symbol' -class MouseInputAdapter
        import java.awt.event.MouseAdapter;
    Also say if I need to get 'column data' from selected
    row, what will be the command like ?
        int col = table.columnAtPoint(p);>
    Best Regards

  • Maximum Allowed Text Length for JTable Column

    Can you please help me with a JTable Doubt
    How do I set the Maximum Allowed Text Length for a Particular Column of a JTable?

    Thanks a lot mate. I used the following
         class MaximumLengthFilter extends DocumentFilter {
                   public void replace(DocumentFilter.FilterBypass fb, int offset, int length,
                             String text, AttributeSet attr) throws BadLocationException {
                        if ((fb.getDocument().getLength() + length) < 10)
                             fb.replace(offset, length, text, attr);
                        else
                             Toolkit.getDefaultToolkit().beep();
              }

  • Tooltip for jtable column?

    Hi, all
    I wrote some code tried to show tooltip on jtable's specific column, but it won't work. The code looks like this:
    Vector tooltip=new Vector();
    int i;
    for(i=0;i<10;i++) {
    tooltip.add("<some tooltip string");
    for(i=0;i<tooltip.size();i++) {             
    System.out.println((String)tooltip.get(i));
    ((DefaultTableCellRenderer)demoTable.getCellRenderer(i,1)).setToolTipText((String)tooltip.get(i));
    In the later loop, System.out.println show exactly tooltip text. But when the table show up, all tooltip text show the same text, the last string stored in Vector tooltip. What's wrong with the above code?
    Thanks,

    er - I think this is cos that only one renderer is used, and it's reused for each component.
    if you subclass the DefaultTableCellRenderer, and in the getTableCellRendererComponent() and then set the tooltiptext in there in that method.
    otherwise you will get the incorrect info.
    (I think that's right anyway)
    Phil J

  • FocusLost event for JTable during cell editing

    When a cell in a JTable is getting edited, how can I get notified of the focusLost event? I added the focus listener using JTable.addFocusListener, but the focusLost of the listener is not called when a cell inside the table is getting edited (it works fine otherwise). I am aware of the client property terminateEditOnFocusLost to solve this problem in 1.4 but I can't use it since I am still on 1.3.1_04.
    Suggestions welcome.

    http://forum.java.sun.com/thread.jsp?forum=57&thread=431440

  • How to cancel datagrid itemclick event for one column with a button control

    I have a datagrid that displays rows of data that can be
    edited and deleted. To edit the user clicks on a row and the row
    data appears above in some text fields and user can edit data then
    clicks save and datagrid is refreshed with updated data. Also on
    each row is a delete button. This button will delete the current
    row of data. The conflict is when user clicks on the delete button
    the itemclick event of row is activated and edit fields get filled
    and then data row is deleted. I can create some very inefficient
    code around this, but i rather not. What I would like to do is
    cancel the itemclick event in the delete button column so the
    itemclick event never happens when click on the button. Is this
    possible?

    Just ran across this problem myself. My simple approach is to check the columnIndex in the ListEvent that is passed on itemClick.

  • 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

  • Different number of rows for different columns in JTable

    hi
    I need to create a JTable with different number of rows for different columns...
    Also the rowheight should be different in each column...
    say there is a JTable with 2 columns... Col1 having 5 rows and column 2 having 2 rows...
    The rowHeight in Col2 should be an integer multiple of Rowheight in Col1
    how do I do this ??
    can anybody send me some sample code ?????
    thanx in advance

    How about nesting JTables with 1 row and many columns in a JTable with 1 column and many rows.
    Or you could leave the extra columns null/blank.
    You could use a GridBagLayout and put a panel in each group of cells and not use JTable at all.
    It would help if you were more specific about how you wanted it to appear and behave.

  • 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.

  • I movie 11: how do i find an event for a particular clip in my project

    I movie 11: how do i find an event for a particular clip in my project

    Thanks so much for your response.  I tried that though and it did not work... any other suggestions?

  • How To Search For a Text In JTable Column?

    hi there
    i want to search for specific text in a JTable Column
    And If The Text Exists Highlits it?
    any ideas or useful links or tutorials?

    Well, then that would be a Swing related question. Did you search the Swing forum to see how rendering works.

  • How do I change the image selected for the finalized movies pane in all events?

    How do I change the image selected for the finalized movies pane in all events? I made a movie some time ago in iMovie, and a still from this now appears as the image for Finalized Movies in the All Events pane (as well as showing up if I then click on this pane to take me to Finalized Movies). Anyone know how to change or delete this image, please?

    Unfortunately, the suggested solution in that thread does not work and the thread appears to be closed to replies.  That is, even though I am logged in the Reply|Quote|Mark as answer|Report as abuse items are missing.
    The suggested solution is:
    First, I found I had "img100.png" in  C:\Windows\Web\Screen  and
    C:\Windows\WinSxS\x86_microsoft-windows-themeui-client_31bf3856ad364e35_6.2.9200.16384_none_69ee3fa2269e545e
    1. Belonging to the Administrators Group, I replaced file Owner TrustedInstaller with my Username on both "img100.png" files
    2. After resizing the image I wanted to see on the Login screen to the resolution of "img100.png" file,
    I copied and pasted it to both "img100.png" files keeping this way the format (extension) and resolution of the original "img100.png" file,
    which I permanently deleted.
    However, I have not been able to replace the img100.pgn in C:\Windows\Web\Screen even after taking ownership of it and setting the permissions for my userid to All.  I edit it with mspaint and then try to save it. The save starts that then says the
    save was interrupted.
    The appears to be some additional protection besides the standard acls.
    http://www.saberman.com

Maybe you are looking for

  • How to connect my Satellite 5000-104 to a TV?

    Hi, hopefully someone can help. I've got an old Toshiba S5000-104 which works perfectly. However, I wanted to connect it to a TV display and there is a very strange combined video-out/line out connector (not a standard composite or s-video) and I do

  • I cannot burn a cd in itunes on my macbook pro

    for some reason when i put a cd in and try to burn a playlist a message flashes on itunes saying " disk burner or software not found" however i definitely made a cd on this computer before. anybody got any tips?

  • Is it possible conversion DataSource to byte[ ] ?

    Hello to all.... I�m a Student, and I can understand JMF, but I have this question. Sorry about my english, but I only need a few things.... 1. is it possible to convert a DataSource to byte[ ] ??, I need the DataSource in bytes. In other words the b

  • Why Same UI Page Behaves Differently on Different EBS Env.?

    Hi Experts, I'm checking Accessibility of our UI page in EBS, on Firefox. There are two EBS env. having the same codeline R12.2. On one env., the page shows fine, but the other one shows "No ALT text specified" for the button/graph, etc. Our product

  • What's required to upgrade from 1.4.0 to 1.4.2?

    I've got four Xserve RAIDs in a single Xsan, with two MDCs (both PowerPC Xserves running OS X Server 10.4.11). They were running Xsan 1.4.0, which meant a lot of our Leopard clients were reporting incorrect sizes for files -- like, video files that w