Selecting JTable continuous/discontinuous rows programatically

Hi!!
I am having a set on table row indexes which I need to programatically select...I am doing following way...
String[] indexes = {2, 4, 6, 1, 9};
table.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
for(int i = 0; i < indexe.length; i++)
table.setRowSelectionInterval(indexes, indexes[i]);
but..only the last row of indexes is getting selected....in this case 10th row....can any body please help me out in selecting all tghe rows in the indexes array...
Thanks
Vikram

grrr.... i want to be able to edit my last posts... :)
has to be addRowSelectionInterval, not SET...
int[] indexes = {2, 4, 6, 1, 9};
table.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
for(int i = 0; i < indexes.length; i++)
table.addRowSelectionInterval(indexes[ i ], indexes[ i ]);

Similar Messages

  • JTable checkboxes doesn't retain their selection when a new row is added!!

    HI,
    My gui has the JTable component which has 5 columns. out of which 4 columns are checkboxes. whenever i select an item from the Jlist and click on the add button it will add a new row in JTable.
    but the problem is whenever a new row is added to the table. the previously selected checkboxes of previous rows are being deselected. But i want to retain the selection of my previous rows even when a new row is added. please help me how to achieve this..i am posting my JTable code here:
    class FunctionTableModel extends AbstractTableModel{
           /** The instances who's attribute structure we are reporting */
        //protected InitModel m_init;
        protected String func_element;
        protected int counter;
        //protected String[] func_array;
        protected Vector func_vector;
        /** The flag for whether the instance will be included */
        protected boolean [] m_Sum;
        protected boolean [] m_Min;
        protected boolean [] m_Avg;
        protected boolean [] m_Max;
        protected boolean [] m_SD;
         * Creates the tablemodel with the given set of instances.
         * @param instances the initial set of Instances
        public FunctionTableModel() {
          counter =0;
             func_vector = new Vector();
         public FunctionTableModel(Vector vec) {
            func_vector = vec;
        public Vector getDataVector(){
            return func_vector;
         * Sets the tablemodel to look at a new set of instances.
         * @param instances the new set of Instances.
        public void setElement(Vector vec) {
               for(int i=0;i<vec.size();i++){
            func_vector.add(vec.elementAt(i));
            counter++;
          fireTableDataChanged();   
          m_Sum = new boolean [counter];
          m_Min = new boolean[counter];
          m_Avg = new boolean[counter];
          m_Max = new boolean[counter];
          m_SD = new boolean[counter];
         * Gets the number of attributes.
         * @return the number of attributes.
        public int getRowCount() {
               return func_vector.size();
         * Gets the number of columns: 3
         * @return 3
        public int getColumnCount() {
          return 6;
         * Gets a table cell
         * @param row the row index
         * @param column the column index
         * @return the value at row, column
        public Object getValueAt(int row, int column) {
          switch (column) {
          case 0:
            return func_vector.elementAt(row);
          case 1:
            return new Boolean(m_Sum[row]);
          case 2:
            return new Boolean(m_Min[row]);
          case 3:
            return new Boolean(m_Avg[row]);
          case 4:
            return new Boolean(m_Max[row]);
          case 5:
            return new Boolean(m_SD[row]); 
          default:
            return null;
        public void removeAll(){
            func_vector.removeAllElements();
            fireTableDataChanged();
         * Gets the name for a column.
         * @param column the column index.
         * @return the name of the column.
        public String getColumnName(int column) {
          switch (column) {
          case 0:
            return new String("Function Selected");
          case 1:
            return new String("Sum");
          case 2:
            return new String("Min");
          case 3:
            return new String("Avg");
          case 4:
            return new String("Max");
          case 5:
            return new String("SD");   
          default:
         return null;
         * Sets the value at a cell.
         * @param value the new value.
         * @param row the row index.
         * @param col the column index.
        public void setValueAt(Object value, int row, int col) {
          if(col == 0){
            counter++;
            func_vector.add(counter,value.toString());
          if (col == 1)
            m_Sum[row] = ((Boolean) value).booleanValue();
          if (col == 2)
            m_Min[row] = ((Boolean) value).booleanValue();
          if (col == 3)
            m_Avg[row] = ((Boolean) value).booleanValue();
          if (col == 4)
            m_Max[row] = ((Boolean) value).booleanValue();
          if (col == 5)
            m_SD[row] = ((Boolean) value).booleanValue();       
         * Gets the class of elements in a column.
         * @param col the column index.
         * @return the class of elements in the column.
        public Class getColumnClass(int col) {
             return getValueAt(0, col).getClass();
         * Returns true if the column is the "selected" column.
         * @param row ignored
         * @param col the column index.
         * @return true if col == 1.
        public boolean isCellEditable(int row, int col) {
          if (col >= 1) {
             return true;
          return false;
        public void removeRow(int row){
            if(row<=func_vector.size()){
                          func_vector.removeElementAt(row);
                counter--;
            fireTableDataChanged();
        }

    hi parvathi,
    i have made changes to my previous code and here's the code:
      class FunctionTableModel extends DefaultTableModel{
           /** The instances who's attribute structure we are reporting */
        //protected InitModel m_init;
        protected String func_element;
        protected int counter;
        protected int counter1;
        //protected String[] func_array;
        protected Vector func_vector;
        /** The flag for whether the instance will be included */
        protected boolean [] m_Sum;
        protected boolean [] m_Min;
        protected boolean [] m_Avg;
        protected boolean [] m_Max;
        protected boolean [] m_SD;
        //protected Vector m_Sum1;
        //protected Vector m_Min1;
        //protected Vector m_Avg1;
        //protected Vector m_Max1;
        //protected Vector m_SD1;
         * Creates the tablemodel with the given set of instances.
         * @param instances the initial set of Instances
        public FunctionTableModel() {
            System.out.println("entered the constr");
          counter =0;
          //counter1=0;
          //m_Sum1 = new Vector();
          //m_Min1 = new Vector();
          //m_Avg1 = new Vector();
          //m_Max1 = new Vector();
          //m_SD1 = new Vector();
          //func_array = new String[];
          func_vector = new Vector();
         public FunctionTableModel(Vector vec) {
            func_vector = vec;
            //setElement(func_vector);
        public Vector getDataVector(){
            return func_vector;
         * Sets the tablemodel to look at a new set of instances.
         * @param instances the new set of Instances.
        public void addRow(Vector vec) {
          //counter++; 
          //func_element = ele;
          //System.out.println("FunctionTableModel- setElement() method");
          for(int i=0;i<vec.size();i++){
            func_vector.add(vec.elementAt(i));
            counter++;  
           //System.out.println("counter ="+counter+new boolean[counter]); 
            //m_Sum1 = m_Sum;
            //m_Min1 = m_Min;
            //m_Avg1 = m_Avg;
            //m_Max1 = m_Max;
            //m_SD1 = m_SD;
            //m_Sum = new boolean[counter];
            //System.out.println("at setElement");
            m_Sum = new boolean[counter];
            //System.out.println(counter);
            m_Min = new boolean[counter];
            //m_Min;
            m_Avg = new boolean[counter];
            //m_Avg1 = m_Avg;
            m_Max = new boolean[counter];
            //m_Max1 = m_Max;
            m_SD = new boolean[counter];
            //m_SD1 = m_SD;
            //counter1++;
          //func_array[counter]=ele;
          //func_vector.add(counter,ele);
          fireTableDataChanged();  
         * Gets the number of attributes.
         * @return the number of attributes.
        //public int getRowCount() {
          //System.out.println("FunctionTableModel- getRowCount() method");
          //return func_vector.size();
         * Gets the number of columns: 3
         * @return 3
        public int getColumnCount() {
          return 6;
         * Gets a table cell
         * @param row the row index
         * @param column the column index
         * @return the value at row, column
        public Object getValueAt(int row, int column) {
          switch (column) {
          case 0:
            return func_vector.elementAt(row);
          case 1:{
            //System.out.println("in case 1");
            //Boolean m_Sum_Value = new Boolean(m_Sum[row]);
            //System.out.println("m_Sum_Value:"+m_Sum_Value.booleanValue());
            return new Boolean(m_Sum[row]);
            //m_Sum1.add(m_Sum_Value);
            //return m_Sum_Value;
          case 2:
            return new Boolean(m_Min[row]);
          case 3:
            return new Boolean(m_Avg[row]);
          case 4:
            return new Boolean(m_Max[row]);
          case 5:
            return new Boolean(m_SD[row]); 
          default:
            return null;
        public void removeAll(){
            func_vector.removeAllElements();
            //m_Sum1.removeAllElements();
            fireTableDataChanged();
         * Gets the name for a column.
         * @param column the column index.
         * @return the name of the column.
        public String getColumnName(int column) {
          switch (column) {
          case 0:
            return new String("Function Selected");
          case 1:
            return new String("Sum");
          case 2:
            return new String("Min");
          case 3:
            return new String("Avg");
          case 4:
            return new String("Max");
          case 5:
            return new String("SD");   
          default:
         return null;
         * Sets the value at a cell.
         * @param value the new value.
         * @param row the row index.
         * @param col the column index.
        public void setValueAt(Object value, int row, int col) {
          if(col == 0){
            counter++;
            func_vector.add(counter,value.toString());
          if (col == 1) {
            m_Sum[row] = ((Boolean) value).booleanValue();
            //System.out.println("m_Sum length "+m_Sum.length);
            //for(int i=0;i<=row;i++)
            //    System.out.println("m_Sum1 "+i+((Boolean)m_Sum1.elementAt(i)).booleanValue());
            //System.out.println("m_Sum1["+row+"] "+ ((Boolean)m_Sum1.elementAt(row)).booleanValue());
            //    System.out.println("m_Sum["+i+"] "+ m_Sum);
    if (col == 2)
    m_Min[row] = ((Boolean) value).booleanValue();
    if (col == 3)
    m_Avg[row] = ((Boolean) value).booleanValue();
    if (col == 4)
    m_Max[row] = ((Boolean) value).booleanValue();
    if (col == 5)
    m_SD[row] = ((Boolean) value).booleanValue();
    * Gets the class of elements in a column.
    * @param col the column index.
    * @return the class of elements in the column.
    public Class getColumnClass(int col) {
    return getValueAt(0, col).getClass();
    * Returns true if the column is the "selected" column.
    * @param row ignored
    * @param col the column index.
    * @return true if col == 1.
    public boolean isCellEditable(int row, int col) {
    if (col >= 1) {
         return true;
    return false;
    public void removeRow(int row){
    if(row<=func_vector.size()){
    func_vector.removeElementAt(row);
    counter--;
    fireTableDataChanged();
    previouslu i was using the setElement method. now i have replaced with the addRow method...
    but anyways...the control is not going to any of these overridden methods...and none of the elements are added to the table. But i comment of all the addRow, getValueAt, getColumnClass methods...then it's adding rows to the table but with only the first column all the remaiing columns are just empty...
    i am fed up with this...if you observe i have commented out somany lines...becoz i am trying to save my boolean array values into a vector..but that was also in vain...
    i appreciate for ur help...
    thanks
    sri

  • How to select more than one row in a JTable swing adf adf?

    how to select more than one row in a JTable swing adf adf?

    // Allow selection to span one contiguous set of rows, visible columns, or block of cells
    table.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
    // Allow multiple selections of rows, visible columns, or cell blocks
    table.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);

  • Select or deselect multiple rows with one single selection  event

    Does anyone know how to create a JTable which can select or deselect multiple rows with one single selection event in JTable. Fore example, if the table has
    row1
    row2
    row3
    row4
    row5
    row6
    What I need is when user select row1 or row2, both row1 and row2 should be set to be selected. Then if user press CTRL and click one of row3 or row4, both of them should be selected including the previouse selected row1 and row2.
    For deselection, if row1 and row2 are selected, when users deselect one of row1 or row2, both of them should be deselected.
    Hopefully someone can give me a hint.

    Here is a partial solution using a JList. Only one line gets highlighted when the user makes a selection in the list. But, two lines are returned. There is a blank line between every two lines.
         private void addLineToList() {
              String a = f_one.getText();
              String b = f_two.getText();
              if (a.length() == 0) {
                   Utils.showInformationMessage("Item field is empty.");
                   f_one.requestFocusInWindow();
                   return;
              if (b.length() == 0) {
                   Utils.showInformationMessage("Match field is empty.");
                   f_two.requestFocusInWindow();
                   return;
              model.addElement("item: " + a);
              model.addElement("match: " + b);
              model.addElement(" ");
              int size = model.getSize();
              pairList.setSelectedIndex(size - 3);
              f_one.setText("");
              f_two.setText("");
              f_one.requestFocusInWindow();
         private void editList() {
              if (pairList.getSelectedValue().toString().equalsIgnoreCase(" ")) {
                   Toolkit.getDefaultToolkit().beep();
                   f_one.requestFocusInWindow();
                   return;
              if (!f_one.getText().equals("")) {
                   int result = JOptionPane.showConfirmDialog(this,
                   "The Item field contains text. Replace the text?",
                   "Flash Card Activity", JOptionPane.YES_NO_OPTION,
                   OptionPane.INFORMATION_MESSAGE);
                   if (result == JOptionPane.NO_OPTION) return;
              if (!f_two.getText().equals("")) {
                   int result = JOptionPane.showConfirmDialog(this,
                   "The Match field contains text. Replace the text?",
                   "Flash Card Activity", JOptionPane.YES_NO_OPTION,
                   JOptionPane.INFORMATION_MESSAGE);
                   if (result == JOptionPane.NO_OPTION) return;
              String item = "";
              String match = "";
              int index = pairList.getSelectedIndex();
              String choice = model.getElementAt(index).toString();
              if (choice.startsWith("item")) {
                   item = choice;
                   match = model.getElementAt(index + 1).toString();
                   model.remove(index);
                   model.remove(index);
                   model.remove(index);
              else {
                   item = model.getElementAt(index - 1).toString();
                   match = choice;
                   model.remove(index + 1);
                   model.remove(index);
                   model.remove(index - 1);
              int size = model.getSize();
              if (size > 2) {
                   pairList.setSelectedIndex(size - 2);
              f_one.setText(item.substring(6));
              f_two.setText(match.substring(7));
              f_one.requestFocusInWindow();
         }

  • How do I select a range of rows from an internal table in the debugger?

    Hi,
    I have a case where I wanted to delete a range of rows (several thousand) from an internal table using the debugger.
    It seems that rows can only be selected one at a time by selecting (clicking) on the far left side of the row.
    This is cumbersome, if not impossible when wishing to delete several thousand rows. 
    Other tools, such as Excel for example, allow for selecting a range of rows by selecting the first row and then holding the SHIFT key and selecting the last row and all rows in between will be selected.
    I can't seem to find the combination of keys that will allow this in the table (or structure) tab of the debugger.
    Is it possible to select a range of rows without having to select each row one at a time?
    Thanks for your help,
    Andy

    While it's a Table Control and should/could have a button to select all fields (or visible fields)...I don't think we can do it right now...I know it's a pain to select each row one at a time...but I don't we have any more options...
    Greetings,
    Blag.

  • Select Count(*) and actual row are differ: 136 rows vs 65k x 7 rows

    Dear All,
    Good morning. Need your advices. We had a view which is running and producing output to excel files. But recently after one of ours database migration, it were producing differ result: Select Count(*) and actual row are differ: 136 rows vs 65k x 7 rows. Error happen when we export out the row to csv file is produced 65000 rows x 7 worksheep. But when perform select count(*) from RTNEWWIP, result return: 136 rows.
    Is there any way to trace below sql to find where go wrong?
    The Veiw as below:
    CREATE OR REPLACE VIEW RTNEWWIP
    (FAB_ID, PO, PRD_NO, SHP_PRD_NO, LOT,
    WIP_QTY, ROUTEDESC, IN_TIME, STAY_DAY, BACK_DAY,
    WO_FCST_DATE, SHIP_FCST_DATE, SHIP_CONF_DATE, WS_DATE, ROUTERATIO,
    PROCESS, LOTSTATUS, LOTTYPE, RETICLEVERSION, PROCESSVERSION,
    ROUTESEQUENCE, PRIORITY, PROCESSGEN, PROCESSFAMILY)
    AS
    select
    --ord.order_no,
    'SILTERRA' FAB_ID,
    wip.PO_NUMBER PO,
    wip.FW_DEVICE PRD_NO,
    wip.USER_ITEM_DESCRIPTION SHP_PRD_NO,
    wip.LOT_ID LOT,
    wip.CURR_QTY WIP_QTY,
    wip.STEP_DESC ROUTEDESC,
    to_char(wip.RECORD_START_DATE,'DD-MON-YYYY HH24:MI:SS') IN_TIME,
    to_char((sysdate - wip.RECORD_START_DATE),'9999D99') STAY_DAY,
    to_char((wip.SCHEDULED_COMPLETE_DATE - sysdate),'9999D99') BACK_DAY,
    -- (sysdate - wip.RECORD_START_DATE) STAY_DAY,
    -- (wip.SCHEDULED_COMPLETE_DATE - sysdate) BACK_DAY,
    to_char(wip.SCHEDULED_COMPLETE_DATE,'DD-MON-YYYY') WO_FCST_DATE,
    to_char((wip.SCHEDULED_COMPLETE_DATE + 1),'DD-MON-YYYY') SHIP_FCST_DATE,
    --nvl(oel.attribute15, to_char(sysdate+3650,'DD-MON-YYYY')) SHIP_CONF_DATE,
    to_char(nvl(to_date(oel.attribute15,'DD-MON-YYYY'), sysdate+3650),'DD-MON-YYYY') SHIP_CONF_DATE,
    to_char(wip.LOT_START_DATE,'DD-MON-YYYY') WS_DATE,
    --wip.MASK_NO || '/' || wip.MASK_TOTAL ROUTERATIO,
    '''' ||wip.MASK_NO || '/' || wip.MASK_TOTAL ROUTERATIO,
    wip.PLAN_NAME_ACTIVE PROCESS,
    wip.LOT_STATUS LOTSTATUS,
    wip.LOT_TYPE LOTTYPE,
    0 RETICLEVERSION,
    wip.PLAN_VERSION_ACTIVE PROCESSVERSION,
    0 ROUTESEQUENCE,
    wip.PRIORITY PRIORITY,
    ' ' PROCESSGEN,
    ' ' PROCESSFAMILY
    from wip_report wip, lot_fact lf, order_fact orf, order_dim ord,
    apps.oe_order_headers_all@prod_myfabetl oeh,
    apps.oe_order_lines_all@prod_myfabetl oel
    where wip.CUSTNAME like 'Realtek%'
    --AND WIP.FW_DEVICE like '%R25C'
    and wip.ACTIVE_FACT_KEY = lf.RECORD_KEY
    and lf.ORDER_FACT_KEY = orf.RECORD_KEY
    and orf.ORDER_KEY = ord.RECORD_KEY
    and ord.ORDER_NO = to_char(oeh.order_number)
    and oeh.header_id = oel.header_id
    and orf.LINE_ITEM_NUMBER = to_char(oel.line_number)
    and orf.ITEM_SCHEDULE = to_char(oel.shipment_number)
    and wip.LOT_TYPE in ('ENX','PRA','PRD','PRT','CSK','MPW')
    union all
    select --od.order_no,'
    'SILTERRA' FAB_ID,
    od.CUST_PO PO,
    imd.FW_DEVICE_ID PRD_NO,
    nvl(orf.USER_ITEM_DESCRIPTION, nvl(imd.CUST_DEVICE_ID, imd.FW_DEVICE_ID)) SHP_PRD_NO,
    sfl.LOTID LOT,
    sfl.currentcompqty WIP_QTY,
    'CREATED' ROUTEDESC,
    to_char(to_date(substr(recordstartdate,1, 14), 'yyyymmddhh24miss'), 'DD-MON-YYYY HH24:MI:SS') IN_TIME,
    --sysdate - to_date(substr(recordstartdate,1, 14), 'yyyymmddhh24miss') STAY_DAY,
    --to_date(sfl.scheduledcompletedate,'yyyymmdd') - sysdate BACK_DAY,
    to_char(sysdate - to_date(substr(recordstartdate,1, 14), 'yyyymmddhh24miss'),'9999D99') STAY_DAY,
    to_char(to_date(sfl.scheduledcompletedate,'yyyymmdd') - sysdate,'9999D99')BACK_DAY,
    to_char(to_date(sfl.scheduledcompletedate,'yyyymmdd'),'DD-MON-YYYY') WO_FCST_DATE,
    to_char(to_date(sfl.scheduledcompletedate,'yyyymmdd') + 1, 'DD-MON-YYYY') SHIP_FCST_DATE,
    --nvl(oel.attribute15, to_char(sysdate+3650,'DD-MON-YYYY')) SHIP_CONF_DATE,
    to_char(nvl(to_date(oel.attribute15,'DD-MON-YYYY'), sysdate+3650),'DD-MON-YYYY') SHIP_CONF_DATE,
    to_char(to_date(sfl.startdate,'yyyymmdd'), 'DD-MON-YYYY') WS_DATE,
    ' ' ROUTERATIO,
    sfl.tempprocessplan PROCESS,
    sfl.currentstatus LOTSTATUS,
    sfl.currenttype LOTTYPE,
    0 RETICLEVERSION,
    0 PROCESSVERSION,
    0 ROUTESEQUENCE,
    ' ' PRIORITY,
    ' ' PROCESSGEN,
    ' ' PROCESSFAMILY
    from SIL_FW_LOTCREATED_VIEW sfl, order_dim od, order_fact orf, item_master_dim imd,
    apps.oe_order_headers_all@prod_myfabetl oeh,
    apps.oe_order_lines_all@prod_myfabetl oel
    where substr(sfl.salesorderno,1,instr(sfl.salesorderno,'-',1,1)-1)= to_char(od.ORDER_NO)
    and od.RECORD_KEY = orf.ORDER_KEY
    and od.RECORD_CURRENT_FLAG = 1
    and orf.RECORD_CURRENT_FLAG =1
    and to_char(orf.LINE_ITEM_NUMBER) = substr(sfl.salesorderno,instr(sfl.salesorderno, '-',1,1) +1, (instr(sfl.salesorderno, '.',1,1) -1) - instr(sfl.salesorderno, '-',1,1))
    and to_char(orf.ITEM_SCHEDULE) = substr(sfl.salesorderno,instr(sfl.salesorderno, '.',1,1) +1, length(salesorderno) - instr(sfl.salesorderno, '.',1,1))
    and orf.ITEM_MASTER_KEY = imd.RECORD_KEY
    and sfl.customername = 'Realtek'
    and od.ORDER_NO = to_char(oeh.order_number)
    and oeh.header_id = oel.header_id
    and orf.LINE_ITEM_NUMBER = to_char(oel.line_number)
    and orf.ITEM_SCHEDULE = to_char(oel.shipment_number);
    select count(*) from rtnewwip;
    COUNT(*)
    136
    1 row selected

    query might be referring to different environment/schema as you are using database link to access some tables.
    getting result/count from view means executing query which forms that view. try to run that query separately and see the output.
    it may help you to debug

  • Select more than 1 row

    hi!
    I'm looking for a method that can help me taking out of my database the number of rows I want for each page to be displayed...
    ...something like select the first 10 rows,
    than from 11 to 20 and so on...
    ...can somebody help me?

    Here. Remember to fill in the correct username and password and table and column names in the SQL query.
    Hope it helps.
    Mel.
    import java.sql.*;
    public class DatabaseTest
      public static void main(String[] args)
        ResultSet rs = null;
        /** URL of database */
        String URL = "jdbc:mysql://localhost/database_name";
        /** Username used to connect to database */
        String userName = "username";
        /** Password required to connect to database */
        String password = "password";
        /** Database Driver class name */
        String driverName = "org.gjt.mm.mysql.Driver";
        /** SQL Query **/
        String sql = "SELECT * FROM tablename ORDER BY column_name LIMIT 0, 10";
        //Connection
        Connection connection = null;
        boolean isConnected = false;
        //Statement
        Statement statement;
        try
          //Load the driver
          Class.forName(driverName);
          //Connect to the database
          connection = DriverManager.getConnection(URL, userName, password);
          isConnected = true;
        //Catch an error if we couldn't connect
        catch (Exception e)
          System.err.println("Couldn't connect to database. Error: " + e);
          // Kill the connection object
          connection = null;
          isConnected = false;
        try
          //Create a new statement object
          statement = connection.createStatement();
          //Execute the query
          rs = statement.executeQuery(sql);
          if(!rs.next()) System.out.println("No Results found");
           else
             do
               //Print out the results found in the query
               System.out.println("1: " + rs.getString(1));
               System.out.println("2: " + rs.getString(2));
             while(rs.next());
          statement.close();
          connection.close();     
        } //End of try
        catch (Exception e)
          System.err.println(
            "ERROR: Could not connect to database when executing query" + e);
        } //End of catch
    }

  • How to select data from 3rd row of Excel to insert into Sql server table using ssis

    Hi,
    Iam having Excel files with headers in first two rows , i want two skip that two rows and select data from 3rd row to insert into Sql Server table using ssis.3rd row is having column names.

                                                         CUSTOMER DETAILS
                         REGION
    COL1        COL2        COL3       COL4           COL5          COL6          COL7
           COL8          COL9          COL10            COL11      
    1            XXX            yyyy         zzzz
    2            XXX            yyyy        zzzzz
    3           XXX            yyyy          zzzzz
    4          XXX             yyyy          zzzzz
    First two rows having cells merged and with headings in excel , i want two skip the first two rows and select the data from 3rd row and insert into sql server using ssis
    Set range within Excel command as per below
    See
    http://www.joellipman.com/articles/microsoft/sql-server/ssis/646-ssis-skip-rows-in-excel-source-file.html
    Please Mark This As Answer if it solved your issue
    Please Mark This As Helpful if it helps to solve your issue
    Visakh
    My MSDN Page
    My Personal Blog
    My Facebook Page

  • Can I simulate SELECT * FROM TABLE WHERE ROW IN (1111,2222) using SQLJ

    I have a fct like
    public void fct(String inStr) {
    String str = "SELECT * FROM TABLE WHERE ROW IN" + inStr;
    // then I xecute the query using JDBC connection
    But I want to do the same thisn using SQLJ like:
    public void fct(String inStr) {
    #sql [nctx] iter = { SELECT * FROM TABLE WHERE ROW IN :inStr}
    When I run the second version and give a parameter like "(1111,2222)" it gives
    ORA-01722: invalid number error.
    Is there a way to give parameters to in clauses of SQLJ statements.
    Thanks in regard.

    This is a SQLJ FAQ. You can find the FAQ at:
    http://technet.oracle.com/tech/java/sqlj_jdbc/htdocs/faq.html
    Your question is addressed in the following section:
    http://technet.oracle.com/tech/java/sqlj_jdbc/htdocs/faq.html#variablesizevaluelist
    Note that that section has a typo. The lines:
    ? // populate mynumbers
    #sql { SELECT * FROM tab WHERE col in (:(a[0]),:(a[1]),?};
    should read:
    ... // populate mynumbers
    #sql { SELECT * FROM tab WHERE col in (:(a[0]),:(a[1]),...};
    By the way, with the next release SQLJ will support pasting in of dynamic SQL fragments. Then you'll be able to do pretty much what you are trying to accomplish here (albeit with slightly different syntax). Until then you'd have to use the workarounds from the FAQ.

  • Can I opt out of Verizon Selects and continue to earn rewards?

    When I signed up for Verizon smart rewards I also had to sign up for Verizon selects. Can I now opt out of Verizon selects and continue to earn rewards with Verizon smart rewards?

    If they do get more competition, I do suspect they will quickly change their tune. But for now, they certainly act more like a utility monopoly than a free market competitor.
    Message was edited as required by the Verizon Wireless Terms of Service
    Message was edited by: Admin Moderator

  • ALV: Need to select/deselect all output rows iwth a Button

    Hi All,
    I have an ALV grid displaying a few lines of data.
    User needs a button in the application toolbar to SELECT/DESELECT all rows displayed in the ALV list.
    I am using OO for displaying the layout.
    I want to know if there is a method which can SELECT/DESELECT all displayed rows. If there is no method, is there a workaround of achieving same.
    Just for your info I dont have a check-box as the first colum of my ALV.
    Appreciate your feedback on same.
    Thanks and Regards
    Rajiv

    hi
    chk this out
    TYPE-POOLS : SLIS.
    Tables                                                              *
    TABLES:
      VBRK,
      VBRP.
    Parameters and select options OR SELECTION SCREEN
    SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-001.
    SELECT-OPTIONS:
                S_VBELN FOR VBRK-VBELN.
    SELECTION-SCREEN END OF BLOCK B1.
    Internal Tables                                                     *
    work areas
    DATA: BEGIN OF IT_VBRP OCCURS 0,
           VBELN LIKE VBRK-VBELN,
           POSNR LIKE VBRP-POSNR,
           UEPOS LIKE VBRP-UEPOS,
           FKIMG LIKE VBRP-FKIMG,
           NETWR LIKE VBRP-NETWR,
           MEINS LIKE VBRP-MEINS.
    DATA : END OF IT_VBRP.
    Variables                                                           *
    DATA : GR_ALVGRID TYPE REF TO CL_GUI_ALV_GRID,
           GC_CUSTOM_CONTROL_NAME TYPE SCRFNAME VALUE 'CC_ALV',
           GR_CCONTAINER TYPE REF TO CL_GUI_CUSTOM_CONTAINER,
           GT_FIELDCAT TYPE LVC_T_FCAT,
           GS_LAYOUT TYPE LVC_S_LAYO,
           V_FLAG VALUE 'X'.
    Start of Program                                                    *
          INITIALIZATION.                                               *
    INITIALIZATION.
      S_VBELN-LOW = 1.
      S_VBELN-HIGH = 1000000000.
      S_VBELN-OPTION = 'EQ'.
      S_VBELN-SIGN = 'I'.
      APPEND S_VBELN.
          SELECTION-SCREEN                                              *
    AT SELECTION-SCREEN.
      PERFORM VALIDATION.
          START-OF-SELECTION                                            *
    START-OF-SELECTION.
      PERFORM GET_DATA.
      CALL SCREEN 0100.
          END-OF-SELECTION                                              *
    END-OF-SELECTION.
          TOP-OF-PAGE                                                   *
    TOP-OF-PAGE.
          END-OF-PAGE                                                   *
    END-OF-PAGE.
          AT USER-COMMAND                                               *
    *&      Form  VALIDATION
          text
    -->  p1        text
    <--  p2        text
    FORM VALIDATION .
      SELECT SINGLE VBELN
      FROM VBRK
      INTO VBRK-VBELN
      WHERE VBELN IN S_VBELN.
      IF SY-SUBRC <> 0.
        MESSAGE E000 WITH 'no billing documents found'.
      ENDIF.
    ENDFORM.                    " VALIDATION
    *&      Form  GET_DATA
          text
    -->  p1        text
    <--  p2        text
    FORM GET_DATA .
      SELECT VBELN
             POSNR
             UEPOS
             FKIMG
             NETWR
             MEINS
      FROM VBRP
      INTO TABLE IT_VBRP
      WHERE VBELN IN S_VBELN.
    ENDFORM.                    " GET_DATA
    *&      Module  DISPLAY_ALV  OUTPUT
          text
    MODULE DISPLAY_ALV OUTPUT.
      IF V_FLAG = 'X'.
        PERFORM DISPLAY_ALV.
        PERFORM PREPARE_FIELD_CATALOG CHANGING GT_FIELDCAT.
        PERFORM PREPARE_LAYOUT CHANGING GS_LAYOUT.
        CALL METHOD GR_ALVGRID->SET_TABLE_FOR_FIRST_DISPLAY
            EXPORTING
         I_BUFFER_ACTIVE               =
         I_BYPASSING_BUFFER            =
         I_CONSISTENCY_CHECK           =
         I_STRUCTURE_NAME              = 'VBRP'
         IS_VARIANT                    =
         I_SAVE                        =
         I_DEFAULT                     = 'X'
              IS_LAYOUT                     = GS_LAYOUT
         IS_PRINT                      =
         IT_SPECIAL_GROUPS             =
         IT_TOOLBAR_EXCLUDING          =
         IT_HYPERLINK                  =
         IT_ALV_GRAPHICS               =
         IT_EXCEPT_QINFO               =
            CHANGING
              IT_OUTTAB                     = IT_VBRP[]
              IT_FIELDCATALOG               = GT_FIELDCAT
         IT_SORT                       =
         IT_FILTER                     =
            EXCEPTIONS
              INVALID_PARAMETER_COMBINATION = 1
              PROGRAM_ERROR                 = 2
              TOO_MANY_LINES                = 3
              OTHERS                        = 4
        IF SY-SUBRC <> 0.
          MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
                     WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
          CALL METHOD GR_ALVGRID->SET_READY_FOR_INPUT
            EXPORTING
              I_READY_FOR_INPUT = 1.
        ELSE.
          CALL METHOD GR_ALVGRID->REFRESH_TABLE_DISPLAY
       EXPORTING
         IS_STABLE      =
         I_SOFT_REFRESH =
            EXCEPTIONS
              FINISHED       = 1
              OTHERS         = 2
          IF SY-SUBRC <> 0.
            MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
                       WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
          ENDIF.
        ENDIF.
        CLEAR V_FLAG.
      ENDIF.
    ENDMODULE.                 " DISPLAY_ALV  OUTPUT
    *&      Form  DISPLAY_ALV
          text
    -->  p1        text
    <--  p2        text
    FORM DISPLAY_ALV .
      IF GR_ALVGRID IS INITIAL.
        CREATE OBJECT GR_ALVGRID
          EXPORTING
       I_SHELLSTYLE      = 0
       I_LIFETIME        =
            I_PARENT          = GR_CCONTAINER
       I_APPL_EVENTS     = space
       I_PARENTDBG       =
       I_APPLOGPARENT    =
       I_GRAPHICSPARENT  =
       I_NAME            =
          EXCEPTIONS
            ERROR_CNTL_CREATE = 1
            ERROR_CNTL_INIT   = 2
            ERROR_CNTL_LINK   = 3
            ERROR_DP_CREATE   = 4
            OTHERS            = 5
        IF SY-SUBRC <> 0.
          MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
                     WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
        ENDIF.
      ENDIF.
    ENDFORM.                    " DISPLAY_ALV
    *&      Form  PREPARE_FIELD_CATALOG
          text
         <--P_GT_FIELDCAT  text
    FORM PREPARE_FIELD_CATALOG  CHANGING P_GT_FIELDCAT TYPE LVC_T_FCAT.
      DATA : LS_FCAT TYPE LVC_S_FCAT,
             L_POS TYPE I.
      L_POS = L_POS + 1.
      LS_FCAT-FIELDNAME = 'VBELN'.
      LS_FCAT-TABNAME = 'IT_VBRP'.
      LS_FCAT-COL_POS = L_POS.
      LS_FCAT-SCRTEXT_M = 'Billing Document'.
      LS_FCAT-OUTPUTLEN = '10'.
      APPEND LS_FCAT TO P_GT_FIELDCAT.
      CLEAR LS_FCAT.
      L_POS = L_POS + 1.
      LS_FCAT-FIELDNAME = 'POSNR'.
      LS_FCAT-TABNAME = 'IT_VBRP'.
      LS_FCAT-COL_POS = L_POS.
      LS_FCAT-SCRTEXT_M = 'Billing Item'.
      LS_FCAT-OUTPUTLEN = '6'.
      APPEND LS_FCAT TO P_GT_FIELDCAT.
      CLEAR LS_FCAT.
      L_POS = L_POS + 1.
      LS_FCAT-FIELDNAME = 'UEPOS'.
      LS_FCAT-TABNAME = 'IT_VBRP'.
      LS_FCAT-COL_POS = L_POS.
      LS_FCAT-SCRTEXT_M = 'Higher Level Item'.
      LS_FCAT-OUTPUTLEN = '6'.
      APPEND LS_FCAT TO P_GT_FIELDCAT.
      CLEAR LS_FCAT.
      L_POS = L_POS + 1.
      LS_FCAT-FIELDNAME = 'FKIMG'.
      LS_FCAT-TABNAME = 'IT_VBRP'.
      LS_FCAT-COL_POS = L_POS.
      LS_FCAT-SCRTEXT_M = 'Invoice Quantity'.
      LS_FCAT-OUTPUTLEN = '13'.
      APPEND LS_FCAT TO P_GT_FIELDCAT.
      CLEAR LS_FCAT.
      L_POS = L_POS + 1.
      LS_FCAT-FIELDNAME = 'NETWR'.
      LS_FCAT-TABNAME = 'IT_VBRP'.
      LS_FCAT-COL_POS = L_POS.
      LS_FCAT-SCRTEXT_M = 'Net Value'.
      LS_FCAT-OUTPUTLEN = '15'.
      APPEND LS_FCAT TO P_GT_FIELDCAT.
      CLEAR LS_FCAT.
      L_POS = L_POS + 1.
      LS_FCAT-FIELDNAME = 'MEINS'.
      LS_FCAT-TABNAME = 'IT_VBRP'.
      LS_FCAT-COL_POS = L_POS.
      LS_FCAT-SCRTEXT_M = 'Unit of Measure'.
      LS_FCAT-OUTPUTLEN = '3'.
      APPEND LS_FCAT TO P_GT_FIELDCAT.
      CLEAR LS_FCAT.
      L_POS = L_POS + 1.
    ENDFORM.                    " PREPARE_FIELD_CATALOG
    *&      Form  PREPARE_LAYOUT
          text
         <--P_GS_LAYOUT  text
    FORM PREPARE_LAYOUT  CHANGING P_GS_LAYOUT TYPE LVC_S_LAYO.
      P_GS_LAYOUT-ZEBRA = 'X'.
      P_GS_LAYOUT-GRID_TITLE = 'INVOICE DETAILS'.
      P_GS_LAYOUT-SMALLTITLE = 'X'.
      P_GS_LAYOUT-EDIT = 'X'.
    ENDFORM.                    " PREPARE_LAYOUT
    *&      Module  STATUS_0100  OUTPUT
          text
    MODULE STATUS_0100 OUTPUT.
      SET PF-STATUS 'CANCEL'.
    SET TITLEBAR 'xxx'.
    ENDMODULE.                 " STATUS_0100  OUTPUT
    *&      Module  USER_COMMAND_0100  INPUT
          text
    MODULE USER_COMMAND_0100 INPUT.
      CASE SY-UCOMM.
        WHEN 'BACK'.
          LEAVE TO SCREEN 0.
        WHEN 'CANCEL'.
          LEAVE TO SCREEN 0.
        WHEN 'EXIT'.
          CALL TRANSACTION 'SE38'.
        WHEN 'CHANGE'.
          IF GR_ALVGRID->IS_READY_FOR_INPUT( ) = 0.
            CALL METHOD GR_ALVGRID->SET_READY_FOR_INPUT
              EXPORTING
                I_READY_FOR_INPUT = 1.
          ELSE.
            CALL METHOD GR_ALVGRID->SET_READY_FOR_INPUT
              EXPORTING
                I_READY_FOR_INPUT = 0.
          ENDIF.
      ENDCASE.
    ENDMODULE.                 " USER_COMMAND_0100  INPUT

  • Changing background color in a selected jtable row

    I have a problem when I call fireTableDataChanged() to change the background color in a table.
    If a row is selected neither getTableCellEditorComponent nor getTableCellRendererComponent is called after fireTableDataChanged()...
    As can you see running this:
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.table.*;   
    //YOU MUST CHANGE IN:
    // import yourpackagename.MyTable.MyTableModel;
    import swing.table.MyTable.MyTableModel;
    public class DemoCellEditor extends javax.swing.JFrame {
         private MyTable myTable1;
         private JScrollPane jScrollPane1;
         private JButton jButton1;
         private AbstractAction abstractAction1;
         static Color red = new Color(200,23,23);
         static Color white = new Color(255,255,255);
         static public Color backgroundColor = white;
         static public Color getBackgroundColor(){ return backgroundColor ;}
         * Auto-generated main method to display this JFrame
         public static void main(String[] args) {
              SwingUtilities.invokeLater(new Runnable() {
                   public void run() {
                        DemoCellEditor inst = new DemoCellEditor();
                        inst.setLocationRelativeTo(null);
                        inst.setVisible(true);
         public DemoCellEditor() {
              super();
              initGUI();
         private void initGUI() {
              try {
                   GroupLayout thisLayout = new GroupLayout((JComponent)getContentPane());
                   getContentPane().setLayout(thisLayout);
                   setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
                        jScrollPane1 = new JScrollPane();
                             myTable1 = new MyTable();
                             jScrollPane1.setViewportView(myTable1);
                        jButton1 = new JButton();
                        jButton1.setText("jButton1");
                        jButton1.setAction(getAbstractAction1());
                   thisLayout.setVerticalGroup(thisLayout.createSequentialGroup()
                        .addContainerGap(43, 43)
                        .addGroup(thisLayout.createParallelGroup()
                            .addGroup(GroupLayout.Alignment.LEADING, thisLayout.createSequentialGroup()
                                .addComponent(jButton1, GroupLayout.PREFERRED_SIZE, 21, GroupLayout.PREFERRED_SIZE)
                                .addGap(0, 151, Short.MAX_VALUE))
                            .addGroup(thisLayout.createSequentialGroup()
                                .addComponent(jScrollPane1, GroupLayout.PREFERRED_SIZE, 172, GroupLayout.PREFERRED_SIZE)
                                .addGap(0, 0, Short.MAX_VALUE)))
                        .addContainerGap(57, 57));
                   thisLayout.setHorizontalGroup(thisLayout.createSequentialGroup()
                        .addContainerGap(48, 48)
                        .addComponent(jScrollPane1, GroupLayout.PREFERRED_SIZE, 162, GroupLayout.PREFERRED_SIZE)
                        .addGap(78)
                        .addComponent(jButton1, GroupLayout.PREFERRED_SIZE, 130, GroupLayout.PREFERRED_SIZE)
                        .addContainerGap(111, Short.MAX_VALUE));
                   pack();
              } catch (Exception e) {
                   e.printStackTrace();
         private AbstractAction getAbstractAction1() {
              if(abstractAction1 == null) {
                   abstractAction1 = new AbstractAction("Change color", null) {
                        public void actionPerformed(ActionEvent evt) {
                             if(backgroundColor == white)
                                  backgroundColor = red;
                             else
                                  backgroundColor = white;
                             ((MyTableModel)myTable1.getModel()).fireTableDataChanged();
              return abstractAction1;
    class MyTable extends JTable
         public MyTable()
              setModel(new MyTableModel());
              setDefaultRenderer(Boolean.class, new TickTableCheckBoxRenderer());
              setDefaultEditor(Boolean.class, new TickTableCheckBoxRenderer());
             class MyTableModel extends AbstractTableModel {
                 private String[] columnNames = {"Check box"};
                 private Object[][] data = { {new Boolean(true)},
                                                    {new Boolean(true)},
                                                    {new Boolean(true)},
                                                    {new Boolean(true)}};
                 public int getColumnCount() {
                     return columnNames.length;
                 public int getRowCount() {
                     return data.length;
                 public String getColumnName(int col) {
                     return columnNames[col];
                 public Object getValueAt(int row, int col) {
                     return data[row][col];
                  * JTable uses this method to determine the default renderer/
                  * editor for each cell.  If we didn't implement this method,
                  * then the last column would contain text ("true"/"false"),
                  * rather than a check box.
                 public Class getColumnClass(int c) {
                     return getValueAt(0, c).getClass();
                 public boolean isCellEditable(int row, int col) {
                       return true;
                 public void setValueAt(Object value, int row, int col) {
                     data[row][col] = value;
                     fireTableCellUpdated(row, col);
    class TickTableCheckBoxRenderer extends AbstractCellEditor
         implements TableCellEditor,TableCellRenderer, ActionListener
         JCheckBox checkBox;
         public TickTableCheckBoxRenderer()
              checkBox = new JCheckBox();
             checkBox.setHorizontalAlignment(SwingConstants.CENTER);
             checkBox.addActionListener(this);
         public Component getTableCellRendererComponent(JTable
                                             table, Object value, boolean isSelected, boolean
                                             hasFocus, int row, int column)
         checkBox.setSelected( Boolean.valueOf( value.toString() ).booleanValue() );
         checkBox.setBackground(DemoCellEditor.getBackgroundColor()); 
         return checkBox;
         public Component getTableCellEditorComponent(JTable table, Object value,
                                       boolean isSelected, int row, int column)
         checkBox.setSelected( Boolean.valueOf( value.toString() ).booleanValue() );
         checkBox.setBackground(DemoCellEditor.getBackgroundColor()); 
         return checkBox;
         public Object getCellEditorValue()
         return Boolean.valueOf(checkBox.isSelected());
         public void actionPerformed(ActionEvent actionEvent) {
              System.out.println("selected ="+checkBox.isSelected());  
    }Edited by: snoopybad77 on Mar 27, 2010 3:27 PM

    weel pheraps for compilig it is better without inner class:
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.table.*;    
    public class DemoCellEditor extends javax.swing.JFrame {
         private MyTable myTable1;
         private JScrollPane jScrollPane1;
         private JButton jButton1;
         private AbstractAction abstractAction1;
         static Color red = new Color(200,23,23);
         static Color white = new Color(255,255,255);
         static public Color backgroundColor = white;
         static public Color getBackgroundColor(){ return backgroundColor ;}
         * Auto-generated main method to display this JFrame
         public static void main(String[] args) {
              SwingUtilities.invokeLater(new Runnable() {
                   public void run() {
                        DemoCellEditor inst = new DemoCellEditor();
                        inst.setLocationRelativeTo(null);
                        inst.setVisible(true);
         public DemoCellEditor() {
              super();
              initGUI();
         private void initGUI() {
              try {
                   GroupLayout thisLayout = new GroupLayout((JComponent)getContentPane());
                   getContentPane().setLayout(thisLayout);
                   setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
                        jScrollPane1 = new JScrollPane();
                             myTable1 = new MyTable();
                             jScrollPane1.setViewportView(myTable1);
                        jButton1 = new JButton();
                        jButton1.setText("jButton1");
                        jButton1.setAction(getAbstractAction1());
                   thisLayout.setVerticalGroup(thisLayout.createSequentialGroup()
                        .addContainerGap(43, 43)
                        .addGroup(thisLayout.createParallelGroup()
                            .addGroup(GroupLayout.Alignment.LEADING, thisLayout.createSequentialGroup()
                                .addComponent(jButton1, GroupLayout.PREFERRED_SIZE, 21, GroupLayout.PREFERRED_SIZE)
                                .addGap(0, 151, Short.MAX_VALUE))
                            .addGroup(thisLayout.createSequentialGroup()
                                .addComponent(jScrollPane1, GroupLayout.PREFERRED_SIZE, 172, GroupLayout.PREFERRED_SIZE)
                                .addGap(0, 0, Short.MAX_VALUE)))
                        .addContainerGap(57, 57));
                   thisLayout.setHorizontalGroup(thisLayout.createSequentialGroup()
                        .addContainerGap(48, 48)
                        .addComponent(jScrollPane1, GroupLayout.PREFERRED_SIZE, 162, GroupLayout.PREFERRED_SIZE)
                        .addGap(78)
                        .addComponent(jButton1, GroupLayout.PREFERRED_SIZE, 130, GroupLayout.PREFERRED_SIZE)
                        .addContainerGap(111, Short.MAX_VALUE));
                   pack();
              } catch (Exception e) {
                   e.printStackTrace();
         private AbstractAction getAbstractAction1() {
              if(abstractAction1 == null) {
                   abstractAction1 = new AbstractAction("Change color", null) {
                        public void actionPerformed(ActionEvent evt) {
                             if(backgroundColor == white)
                                  backgroundColor = red;
                             else
                                  backgroundColor = white;
                             ((MyTableModel)myTable1.getModel()).fireTableDataChanged();
                             myTable1.repaint();
              return abstractAction1;
    class MyTable extends JTable
              public MyTable()
                   setModel(new MyTableModel());
                   setDefaultRenderer(Boolean.class, new TickTableCheckBoxRenderer());
                   setDefaultEditor(Boolean.class, new TickTableCheckBoxRenderer());
    class MyTableModel extends AbstractTableModel {
         private String[] columnNames = {"Check box"};
         private Object[][] data = { {new Boolean(true)},
                                               {new Boolean(true)},
                                               {new Boolean(true)},
                                               {new Boolean(true)}};
         public int getColumnCount() {
             return columnNames.length;
         public int getRowCount() {
             return data.length;
         public String getColumnName(int col) {
             return columnNames[col];
         public Object getValueAt(int row, int col) {
             return data[row][col];
          * JTable uses this method to determine the default renderer/
          * editor for each cell.  If we didn't implement this method,
          * then the last column would contain text ("true"/"false"),
          * rather than a check box.
         public Class getColumnClass(int c) {
             return getValueAt(0, c).getClass();
         public boolean isCellEditable(int row, int col) {
               return true;
         public void setValueAt(Object value, int row, int col) {
             data[row][col] = value;
             fireTableCellUpdated(row, col);
    class TickTableCheckBoxRenderer extends AbstractCellEditor
         implements TableCellEditor,TableCellRenderer, ActionListener
         JCheckBox checkBox;
         public TickTableCheckBoxRenderer()
              checkBox = new JCheckBox();
             checkBox.setHorizontalAlignment(SwingConstants.CENTER);
             checkBox.addActionListener(this);
         public Component getTableCellRendererComponent(JTable
                                             table, Object value, boolean isSelected, boolean
                                             hasFocus, int row, int column)
         checkBox.setSelected( Boolean.valueOf( value.toString() ).booleanValue() );
         checkBox.setBackground(DemoCellEditor.getBackgroundColor()); 
         return checkBox;
         public Component getTableCellEditorComponent(JTable table, Object value,
                                       boolean isSelected, int row, int column)
         checkBox.setSelected( Boolean.valueOf( value.toString() ).booleanValue() );
         checkBox.setBackground(DemoCellEditor.getBackgroundColor()); 
         return checkBox;
         public Object getCellEditorValue()
         return Boolean.valueOf(checkBox.isSelected());
         public void actionPerformed(ActionEvent actionEvent) {
              System.out.println("selected ="+checkBox.isSelected());  
    }Edited by: snoopybad77 on Mar 27, 2010 5:20 PM

  • 3.2; BC4J, GridControl; Select row programatically?

    Hi,
    I need to programatically Highlighted a desired row (which i know the primary key) from a grid and scroll the grid to show this selected row in the view port area.
    Any property/way for this ?
    note that: define a WHERE clause for rowSetInfo and .executeQuery() cause to show only the qualified rows. and this is not my purpose.
    Please Advice.
    Ali

    Sathish,KKirk
    With your suggestion i wrote following code.
    It found the desired row and highlighted, but grid doesn't scroll to show this row on the view port.
    So, now how can i scroll the grid to show the row?
    try{
    ScrollableRowsetAccess systemRs = (ScrollableRowsetAccess)SystemViewRowSetInfo.getRowsetAccess();
    systemRs.absolute(1);
    do{
    ImmediateAccess iSys= (ImmediateAccess)systemRs.getColumnItem("SystemCode");
    String sSys = iSys.getValueAsString();
    if (sSys.equals(100)) {
    break;
    }while (systemRs.next());
    }catch(Exception ex){
    ex.printStackTrace();
    null

  • JTable - make 1st row selected by default

    hi,
    i have a JTable, how can i make the 1st row selected by default?
    thanks.

    try table.getSelectionModel().setSelectionInterval(0, 0)
    You need to check and make sure there is at least one row in the table before you do this, otherwise exception will throw.
    Hope this will help.

  • How to get event from selected JTable row

    Whenever a JTable row is selected, i want to get an event to get the row index of the selected row and read the row data. Which listenere do i have to implement and where is the correspoinding addXXXListener() method in JTable?

    here ya go...
    <table>.getSelectionModel().addListSelectionListener(...);Josh Castagno
    http://www.jdc-software.com

Maybe you are looking for

  • New iPod Classic with lightning connector in 2013?

    So I am slowly stepping my apple products game up.  Now all my stuff has the new lightning connector.  What about my ipod classic?  I use that mofo erryday.  I wanna get rid of it but only if they come out with a new one with the lightning connector.

  • Late 2008 MacBook Pro Forgetting date and wifi settings

    I have a 15" refurb MBP 5,1. It just started forgetting the time, date and my 802.11 settings including the WPA encryption key. Previously I made a post in the Power Forum saying that when I plugged in the power adapter I got a message in the upper r

  • Advice on materialized view.

    Hello everybody, I have a question and I hope you can advise. Imagine the following (simplified) model. CREATE TABLE players   player_id NUMBER(15) PRIMARY KEY,   player_name VARCHAR2(100) NOT NULL,   creation_date DATE,   birth_date DATE   -- around

  • 2630 Text messaging- how do I access my contacts?

    I've just been given a 2630 by my employer and I'm having difficulty with text messaging, how do I access my contacts? When I try to create a message it says To: and then seems to expect me to input a phone number, surely it is possible just to pick

  • Blackberry Style PLEASE!!!!!!

    C'mon Verizon, I am begging for you to carry this phone. I love blackberry, switched to android because I wanted a good touch screen with a keyboard.  I truly miss many aspects of my blackberry and love the clamshell form factor.  I know there are th