To setup scrollbars for individual columns in JTable

Hi,
I need to setup individual scrollbars for the
columns in JTable.
Can anybody help?
Thanks in advance.
Rgds,
sita

Hi,
I need to setup individual scrollbars for the
columns in JTable.If i understand you correctly, you want to have a scrollbar for every column. If so, you will need a new instance of JTable and JScrollPane for every column, but that's a lot of work if you want to do it fancy.
The good news, is you can reuse the table model.
You could do something like that.
for (int i= 0; i < model.getColumnCount(); i++) {
    JTable table = new JTable();
    table.setAutoCreateColumnsFromModel(false);
   //container
    someContainer.add(new ScrollPane(table), null/* or some layout constrains*/);
    TableColumn tc = new TableColumn(i, 120);
    tc.setHeaderValue(model.getColumnName(i));
    table.addColumn(tc);
Can anybody help?
Thanks in advance.
Rgds,
sita

Similar Messages

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

  • Prompts for individual columns

    Hi Experts,
    Is there any option for creating prompts for individual columns. means i have to extract data for region,customer,amount1,amount2,amount1+amount2 and % of amount1+amount2.
    But for amount1 i need to extract the data for this financial year and for amount2 is latest month data.
    How to achieve this using prompts.Because client wants those prompts dynamical.
    Please help me.

    Hi,
    If anybody doesn't have a better sollution... let's trick BI...
    to have in one report one mesure that summerize for an entire year, and one masure that is for only one month and we want to filter on that particular month,
    we need to set on measure 1 that it is at year level (so it will always summerize for entire year).
    Now our problem that year is not YEAR(some_date) so for jan 2010 to dec 2010 to give us 2010.
    We want to have from apr 2009 to mar 2010 to be 2009
    so we trick the year map to be
    finanial_year = case when month(some_date) < 4 then year(some_date) - 1 else year(some_date) end
    so now in my measure if I set at levels to financial_year it will summerize from apr to march...
    Hope It helpes
    Regards
    Nicolae

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

  • Suppressing totals for individual columns

    In OBIEE 10.1.3.4 Answers, is there a way to suppress totaling for an individual column? I have a derived column - unit price - that I want to suppress totaling on, while retaining totals for quantity and amount. I can do it by casting the column to character, but figured there must be a better way.
    Never mind... foundit!
    Edited by: andrea.bender on Jul 14, 2011 6:42 AM

    To suppress totaling on a specific column, go into the report and edit the formula for column and set Aggregation Rule to 'None'

  • Setting cell editor for individual cell in JTable

    Hi there,
    I want to provide individual cell editor for my JTable. Basically, my JTable shows property names and values. I want to show different cell editors for different properties.
    I followed the advice in this post:
    http://forum.java.sun.com/thread.jsp?forum=57&thread=423318
    but I have a question:
    I looked at the code of DefaultCellEditor. It just has a single editor component (the one provided in the constructor), so all the methods use the same component and certain aspects are customized for the type of component. Again, there can be only one type of component at a time.The problem that I am facing is that I will have different components for different row/column of the same table. So how do I implement some of the methods (for example, getCellEditorValue()), when I have multiple editor components?
    Also, how do I commit changes made by the user?
    I am extremely confused.
    Someone please help!
    Thanks.

    Actually, that's what I am currently doing.
    Here is my cell editor class:
    public class ObjectPropertyEditor extends DefaultCellEditor
           public ObjectPropertyEditor()
              super(new JTextField());
              Vector list = new Vector();
              list.add("Yes");
              list.add("No");
             myCombo = new JComboBox(list);
          public Component getTableCellEditorComponent(JTable table, Object value,
              boolean isSelected, int row, int column)
             String colName = (String)table.getValueAt(row,0);
             if(colName.equalsIgnoreCase("Leaf-Node?")) //if it is the "Leaf" property, return the combo box as the editor
                 return myCombo;
            else  //for all other properties, use JTextField of the super class
                return super.getTableCellEditorComponent(table,value,isSelected,row,column);
        private JComboBox myCombo;
    }The problem I have is that when I select a new item from the combo box, the new selection is not reflected in the tableModel. I don't know how I can achive that. I think I need the functionalities that DefaultCellEditor gives to its delegate when its constructor arguments is a combo box. But how can I get two different sets of functionalities (JTextField and JComboBox) ?
    Please help!
    Thanks.

  • Disable row selection for certain column in JTable

    I have a JTable with several columns, one of which contains an "Info" button. I already have it worked out that when I click on the "Info" button, that event gets passed from the JTable to the button. I have multi-select enabled for the JTable, but I don't want clicking on the "Info" button to change the current selection. I have a klugy "fix" working where I save off the current selection, and then restore it after the user presses the "Info" button. However, this results in "flashing" - the row containing the selected "Info" button becomes selected briefly, then the original selection is restored. How can I avoid this? I would like to just ignore selection events on the "Info" column, but still pass the mouse click event through to the button.
    Any suggestions?

    try this
            JTable table = new JTable() {
                public void changeSelection(int rowIndex, int columnIndex, boolean toggle, boolean extend) {
                    if (!getColumnModel().getColumn(columnIndex).getIdentifier().equals("Info")) {
                        super.changeSelection(rowIndex, columnIndex, toggle, extend);
                    }//else

  • Setting a background for a column in JTable

    Hi there
    i want to set a background for a specific column in my JTable
    any help ...?
    Thanks

    Check the following thread, there you'll find the cell renderer that you may change according to your needs.
    http://forum.java.sun.com/thread.jsp?forum=31&thread=298191

  • CREATING ITEMS FOR INDIVIDUAL COLUMNS

    HI GUYS!
    i am a new user to HTMLDB. I need help on creating a search item for every single column in the report using pop-up LOV´s(eg:like we have in EXCEL report sheets).
    The pop-up item should display the DISTINCT rows of the column...please give the SQL Query involved in the identification of LOV .

    Hi,
    Let me give you an idea.
    user data dictionery view "user_tab_columns" write a dynamic sql with all of the columns for given table and write another dynamic sql and use the column_name from "user_tab_columns" in the where clause and search the string or number.
    If you need more help I can but I would like you to try yourself.
    Hope this helps
    Ghulam

  • Disable scrollbars for some columns in matrix

    Hi,
    I created a form which includes a matrix. This matrix contains a lot of columns. Because of the amount, the matrix automatically creates a scrollbar at the bottom.
    I don't want the matrix to have a scrollbar on the first and second columns. Is there a possibility to set a column of which the scrollbar starts.
    The form in which the user can enter a forecast (MRP > Forecasts) contains this feature. When specifying a date range in this form, the first two columns are not included in the scrollbar at the bottom of the matrix.
    Can anyone tell me how this is done?
    Thanks in advance!
    Jerrel

    Hi Jerrel,
    I don't think this is possible, but to double-check, please export the MRP>Forecasts form to XML - and check what might be special, but I suppose you won't find anything...
    Other than that you could just define 2 Matrixes and have them just side-by-side - but of course this would get tricky when it comes to vertical scrolling etc.
    ...but maybe someone else has a better idea?
    Regards,
    Frank

  • How to setForeground for individual JTable rows???

    How do you set the foreground and background colors for individual rows in a JTable? I don't want every row to change, just the rows I select programmatically (not via the GUI). The JTable.setForeground() from the JComponent base class changes all the rows. Any ideas?

    Hi!
    Write your own renderer and set it as defaultRenderer on your table. Something like this:
    // Using Object.class makes sure the renderer will be used regardless of column class type
    myTable.setDefaultRenderer(Object.class, new MyRenderer(Color.red));And the renderer:
    class MyRenderer extends javax.swing.table.DefaultTableCellRenderer
        private Color m_mySelectedColor;
        public MyRenderer(Color par_mySelectedColor)
            m_mySelectedColor = par_mySelectedColor;
        public Component getTableCellRendererComponent(JTable table,
                                                       Object value,
                                                       boolean isSelected,
                                                       boolean hasFocus,
                                                       int row,
                                                       int column)
            Component returnComponent = super.getTableCellRendererComponent(
                    table,value,isSelected,hasFocus,row,column);
            if (isSelected)
                returnComponent.setBackground(m_mySelectedColor);
            else
                returnComponent.setBackground(table.getBackground());
            return returnComponent;
    }smedman

  • How do I set individual properties for a column in report layout at runtime

    How do I set individual properties for a column in report layout at runtime? I need to change this based on a user's input. This is for v10g.
    I need to change either the "Read from File" attribute or the "File Format" attribute for one column based on the user's input. IS this possible?
    Thanks in advance!

    Hi,
    define 2 columns and use format triggers to show the one or the other column.
    Regards
    Rainer

  • What method should be used for resizing the particular JTable Column width

    I have a four table. Only one table which are on top have a table header. I want that when user resize the topmost table with a mouse other table colume also be resized automatically. So I want to know that what method should be used for resizing the particular JTable Column width.
    Thanks
    Lalit

    maybe you can implement a interface ComponentListener as well as ComponentAdapter with your topmost Table.
    for example:
    toptable.addComponentListener(
    new ComponentAdapter(){
    public void componentResized(ComponentEvent e){
    table1.setSize(....);
    table2.setSize(....);
    /*Optionally, you must also call function revalidate
    anywhere;*/
    );

  • 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

  • JTABLE - horizontal scrolling only for some columns

    Hi all,
    In my JTABLE I have to scroll the horizontal scrollbar only from column 5 to the last, the columns 0 - 4 should be fixed ! Is this possible ?
    Thanks in advance,
    Arpana

    Please see
    http://www.senun.com/Left/Programming/Java_old/Examples_swing/JTableExamples1.html
    http://www.senun.com/Left/Programming/Java_old/Examples_swing/src/examples/FixedColumnExample.java

Maybe you are looking for

  • Mutilple File Selection and Upload Functionality in Sharepoint 2010

    Hi, I have a requirement that i have to create an Application page where i should have the following functionality. Should be able to select multiple files at a single shot. That is when i click on Browse and choose files i should be able to choose m

  • Backup disk image cannot be mounted.

    I have tried and tried to get Time Machine up and running with no success. It has given me several error messages...the latest of which is "The backup disk image could not be mounted." I can see the disk in my "shared" finder window, make changes but

  • Video input into Mini for live st-reaming

    I want to use a Mac Mini for strea-ming video. Note: I want to broadcast the str-eaming videos, not watch them! I will hook up a camcorder to the Mini, and then stream the video to a str-eaming service. My question: how can I connect the camcorder to

  • IBook and Mac mini

    Hello users... I'd like to know if anyone has helpful information as to whether my iBook G4 can or will Communicate BETTER with my mac mini? I know that they are totally different operating systems but my iBook is perfectly fine and works great, plus

  • TextEdit multiple lines

    Hi, I am working on a requirment where i am using textEdit as a cell in tableView. Every thing is working fine except i am unable to capture the data from textEdit. I have to store the multiple lines entered by user into a z-table column of type XSTR