Trying to get Row numbes to display in a DefaultTableCellRenderer

Hello all.
I have extended the defaultablecellrenderer and have got my JTanle to use it. Howeve, i want to represent the rows of the tables as well as the colums...so far i have managed to colour each row (by colour the first colum of the JTable) is there a wat to number these values, give the number of rows as an arguement? Many thanks, Rupesh.
I call the renderer by
_renderer = new MyTableCellRenderer();
myTable.setDefaultRenderer(Object.class, _renderer );
Btw - when i enter data into my table, it just disappears as soon as i click on another cell..is this because i havent implemented a setValue method in the renderer yet?
import javax.swing.*;
import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.border.*;
import java.awt.Component;
import java.awt.Color;
import java.awt.Rectangle;
import java.util.*;
import java.awt.*;
public class MyTableCellRenderer extends DefaultTableCellRenderer{
     private Font cellFont;
     public MyTableCellRenderer() {
          super();
     private boolean isHeaderCell(int row, int column){return column == 0;}
     public Component getTableCellRendererComponent (JTable myTable, Object value, boolean isSelected, boolean hasFocus, int row, int column){
          if (isSelected && !(isHeaderCell(row,column))){
               super.setForeground(myTable.getSelectionForeground());
               super.setBackground(myTable.getSelectionBackground());
          else{
               if (isHeaderCell (row, column)){
                    super.setBackground(Color.lightGray);
                    super.setForeground(myTable.getForeground());
               else {
               super.setForeground(myTable.getForeground());
               super.setBackground(myTable.getBackground());
     cellFont = new Font("Times", Font.PLAIN, 20);
     setFont(cellFont);
     if (hasFocus) {
          setBorder(UIManager.getBorder("Table.focusCellHighlightBorder"));
          if (myTable.isCellEditable(row,column)) {
               super.setForeground(UIManager.getColor("Table.focusCellForeground"));
               super.setBackground(UIManager.getColor("Tale.focusCellBackground"));
     else {setBorder(noFocusBorder);}
     Color bDis = getBackground();
     boolean colourEquals = (bDis != null) && (bDis.equals(myTable.getBackground()) ) & myTable.isOpaque();
     setOpaque (!colourEquals);
     return this;
}

Maybe this is what you are looking for. This code adds a line number for each row in the table:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.table.*;
public class LineNumberTable extends JTable
    protected JTable mainTable;
    public LineNumberTable(JTable table)
        super();
        mainTable = table;
        setModel(new RowNumberTableModel());
        setPreferredScrollableViewportSize(getPreferredSize());
        getColumnModel().getColumn(0).setPreferredWidth(50);
        getColumnModel().getColumn(0).setCellRenderer( mainTable.getTableHeader().getDefaultRenderer() );
    public int getRowHeight(int row)
        return mainTable.getRowHeight();
    class RowNumberTableModel extends AbstractTableModel
        public int getRowCount()
             return mainTable.getModel().getRowCount();
        public int getColumnCount()
            return 1;
        public Object getValueAt(int row, int column)
            return new Integer(row + 1);
    public static void main(String[] args)
        Object[][] data = { {"1", "A"}, {"2", "B"}, {"3", "C"} };
        String[] columnNames = {"Number","Letter"};
        DefaultTableModel model = new DefaultTableModel(data, columnNames);
        JTable table = new JTable(model);
        JScrollPane scrollPane = new JScrollPane( table );
        JTable lineTable = new LineNumberTable( table );
        scrollPane.setRowHeaderView( lineTable );
        JFrame frame = new JFrame( "Line Number Table" );
        frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
        frame.getContentPane().add(scrollPane, BorderLayout.CENTER);
        frame.setSize(400, 300);
        frame.setVisible(true);
}

Similar Messages

  • How to get row number

    Hi,
    I want to get row number in an table using some condition.
    Any solutions?
    Thanks
    shri

    shri,
    That's nice - you answered one question out of my three.
    Version number of JDev/ADF?
    What technologies are you using, particularly on the model layer?
    and some new ones:
    are you using ADF binding?
    are you trying to display a row number on the table, or determine which row is selected (for example)?
    and do you mean the row number relative to the first row displayed currently, or to the "top" of the table?
    As I said - a proper use case (which would have answered all these questions) would enable you to get some answers. See [url http://www.catb.org/~esr/faqs/smart-questions.html]this if you still don't understand.
    John

  • How to get row number in the fetch row itself in Sql Query ?

    Hi,
    i am fetching some rows from a sql query . Is there any way to get row number as well in each row while all rows are fetched ?
    like this :
    RowNum data1 data2
    1 abc ere
    2 bnh ioi

    Hello
    Ofcourse you can get the rownum inside a query, just keep in mind that the rownum is the number of order in which the records were fetched from the table, so if you do an order by, the rownum will not be sequential, unless you query the information in a subquery first.
    SELECT rown, col1, col1
    FROM table
    Or
    SELECT rownum, col1, col2
    FROM (SELECT col_1, col_2 FROM table ORDER BY col1)
    Regards
    Johan

  • How to get row number of selected entry from OVS search result

    Hi,
    Anyone having any idea on how to get row number of the  selected entry/ how to differentiate rows in OVS search result in ON_OVS method?
    Regards,
    Jatin

    Hi,
    You can get the selected record to <ls_selection> structure in co phase 3.
    From that structure you can get what ever field you want.,
    check the below code for reference,
    << Moderator message - Cut and paste response from F4 help for ALV table field removed. Plagiarism is not allowed in SCN >>
    hope this helps u.,
    Thanks & Regards,
    Kiran
    Edited by: Rob Burbank on Jan 5, 2012 5:24 PM

  • Trying to get row counts for all tables at a time

    Hi,
    i am trying to get row counts in database at a time with below query but i am getting error:
    its giving me ora-19202 error..please advise me
    select
          table_name,
          to_number(
            extractvalue(
              xmltype(dbms_xmlgen.getxml('select count(*) c from '||table_name))
              ,'/ROWSET/ROW/C')
              count
        from all_tables;

    ALL_TABLES returns tables/views current user has access to. These tables/views are owned not just by current user. However your code
    dbms_xmlgen.getxml('select count(*) c from '||table_name)does not specify who the owner is. You need to change it to:
    dbms_xmlgen.getxml('select count(*) c from '||owner || '.' || table_name)However, it still will not work. Why? As I said, ALL_TABLES returns tables/views current user has access to. Any type of access, not just SELECT. So if current user is, for example, granted nothing but UPDATE on some table the above select will fail. You would have to filter ALL_TABLES through ALL_SYS_PRIVS, ALL_ROLE_PRIVS, ALL_TAB_PRIVS and PUBLIC to get list of tables current user can select from. For example, code below does it for tables/views owned by current user and tables/views current user is explicitly granted SELECT:
    select
          t.owner,
          t.table_name,
          to_number(
            extractvalue(
              xmltype(dbms_xmlgen.getxml('select count(*) c from '||t.owner || '.' || t.table_name))
              ,'/ROWSET/ROW/C')
              count
        from all_tables t,user_tab_privs p
        where t.owner = p.owner
          and t.table_name = p.table_name
          and privilege = 'SELECT'
    union all
    select
          user,
          t.table_name,
          to_number(
            extractvalue(
              xmltype(dbms_xmlgen.getxml('select count(*) c from '||t.table_name))
              ,'/ROWSET/ROW/C')
              count
        from user_tables t
    OWNER                          TABLE_NAME                                                          COUNT
    SCOTT                          DEPT                                                                    4
    U1                             QAQA                                                                    0
    U1                             TBL                                                                     0
    U1                             EMP                                                                     1
    SQL> SY.

  • How can I get the row number of display automatically on a table?

    I have a table of measurements, and I would like the row number to be displayed on each row. The challenge is that each time I run the program, the total number of rows will be different, so I would like the numbers to update every time I run the program based on the current number of rows.
    I have attached a picture to illustrate what I am trying to do.
    Solved!
    Go to Solution.
    Attachments:
    picture of table.JPG ‏70 KB

    Find the attached example (saved in version 2009), and you can extract what you need for your code...!!
    I am not allergic to Kudos, in fact I love Kudos.
     Make your LabVIEW experience more CONVENIENT.
    Attachments:
    Example (Enter Row Header).vi ‏12 KB

  • Get row number of record in Interactive Report

    I am using an interactive report and want to be able to modify a field and if the value already exists in the database change it back to what it was originally. I am selecting data using the select statement below and I'm calling the javascript CheckExists function when the value changes. All this is working but I need to figure out how to get the row number so I can change the value back to what is in f03 in the same row. Does anyone know how to access the row number or know how I can do this?
    select apex_item.checkbox(1, RESOURCE_TYPE_ID, 'onchange="CheckUsed(this, this.value);"', ':') "Delete",
    apex_item.text(2, RESOURCE_TYPE, 20, 100, 'onchange="CheckExists(this, this.value);"' ) "RESOURCE_TYPE",
    RESOURCE_TYPE_ID,
    apex_item.text(3, RESOURCE_TYPE, 20, 100) "orig_resource_type"
    from resource_types
    order by RESOURCE_TYPE

    Scott,
    I was not able to find anything like using #ROWNUM# that would give me the current row number but I was able to get it if I looped through all the records until I found the record I was currently on. It is not really what I wanted to do but it works. I have included the code below.
    Thanks a lot for your help I appreciate it.
    Steve
    *** Interactive Report Select statement ***
    select apex_item.checkbox(1, RESOURCE_TYPE_ID, 'onchange="CheckUsed(this);"', ':') "Delete",
    apex_item.text(2, RESOURCE_TYPE, 20, 100, 'onchange="CheckExists(this);"' ) RESOURCE_TYPE,
    RESOURCE_TYPE_ID,
    apex_item.text(3, RESOURCE_TYPE, 20, 100) ORIG_RESOURCE_TYPE
    from resource_types
    order by RESOURCE_TYPE
    *** Javascript ***
    function CheckUsed (pResourceType)
    var get = new htmldb_Get(null,$x('pFlowId').value,'APPLICATION_PROCESS=ResourcesResourceTypeExists',0);
    get.add('TEMPORARY_ITEM', pResourceType.value);
    gReturn = get.get();
    if (gReturn > 0)
    alert('Resource records exist using the Resource Type; Unable to delete.');
    pResourceType.checked=false;
    function CheckExists (pResourceType)
    // Get the current row number.
    var lResourceTypeId = document.getElementsByName("f01");
    var lResourceType = document.getElementsByName("f02");
    var lOrigResourceType = document.getElementsByName("f03");
    var j;
    for (j = 0; j < lResourceType.length; j++)
    if (lResourceType[j].value == pResourceType.value)
    if (lResourceType[j].value != lOrigResourceType[j].value)
    break;
    } // if (lResourceType[j].value != lOrigResourceType[j].value)
    } // if (lResourceType[j].value == pResourceType.value)
    } // for (j = 0; j < lResourceType.length; j++)
    // Check if the Resource Type already exists.
    var get = new htmldb_Get(null,$x('pFlowId').value,'APPLICATION_PROCESS=ResourceTypeExists',0);
    get.add('TEMPORARY_ITEM', pResourceType.value);
    gReturn = get.get();
    if (gReturn > 0)
    // Reset the Resource Type to the original Resource Type.
    get.add('lResourceType[j]', lOrigResourceType[j].value);
    doSubmit('SUBMIT');
    else
    var get = new htmldb_Get(null,$x('pFlowId').value,'APPLICATION_PROCESS=UpdateResourceType',0);
    get.add('TEMPORARY_ITEM', pResourceType.value);
    get.add('TEMPORARY_ITEM_2', lResourceTypeId[j].value);
    gReturn = get.get();
    alert(gReturn );
    }

  • Trying to get serial number to install elements 12.

    I am trying to get the serial number to install elements 12.  Have entered the redemption code but the redeem button does not activate.

    You should try using a different browser if the one you are using is not working with the interface properly.  Below is a link to a help document that might provide some helpful tips if you continue to have a problem.
    Redemption Code Help
    http://helpx.adobe.com/x-productkb/global/redemption-code-help.html

  • Get row number

    Hi list,
    does any one know how I can get the row number the same as what I have in column rowno?
    thanks
    Arvin
    REATE   TABLE dbo.temptable
    ( y int  NOT NULL,
      e int not null,
      c int not null,
      rowno int not null)
    /* insert values  */
    INSERT INTO dbo.temptable(y,e,c,rowno ) VALUES
    (1,123,1,1),
    (1,123,2,1),
    (1,123,3,1),
    (1,5435,1,2),
    (1,5435,2,2),
    (1,5435,3,2),
    (1,83444,1,3),
    (1,83444,1,3),
    (2,111,1,1),
    (2,111,2,1),
    (2,32245,1,2),
    (2,32245,3,2);

    Use Dense_Rank function.
    Refer the below query,
    select *,dense_rank() over (partition by y order by y,e) myrowno from dbo.temptable
    Regards, RSingh

  • Trying to get rows to ResultSet with CallableStatement and stored functio

    Hello!
    I'm using JDBC with Oracle XE 11g2, driver ojdbc6.jar (Oracle Database 11g Release 2 (11.2.0.3) JDBC Drivers, JDBC Thin for All Platforms) from oracle.com
    I've got a table
    CREATE TABLE ORGANIZATIONS
    CODE VARCHAR2(4),
    DESCRIPTION VARCHAR2(255)
    And I'm trying to get all organizations into ResultSet using CallableStatement with stored function:
    CallableStatement cs = connection.prepareCall("{? = call FN_GET_ROWS}");
    cs.registerOutParameter(1, oracle.jdbc.OracleTypes.CURSOR);
    cs.execute();
    I've created two types:
    CREATE OR REPLACE
    TYPE TEST_OBJ_TYPE AS OBJECT (
    CODE VARCHAR2(4),
    DESCRIPTION VARCHAR2(255)
    and
    CREATE OR REPLACE
    TYPE TEST_TABTYPE AS TABLE OF TEST_OBJ_TYPE
    and my function is
    CREATE OR REPLACE
    FUNCTION FN_GET_ROWS RETURN TEST_TABTYPE AS V_Test_Tabtype Test_TabType;
    BEGIN
    SELECT TEST_OBJ_TYPE(A.CODE, A.DESCRIPTION)
    BULK COLLECT INTO V_Test_TabType
    FROM
    (SELECT CODE, DESCRIPTION
    FROM ASM.ORGANIZATIONS
    ) A;
    RETURN V_Test_TabType;
    END;
    but when I run my program I've got error:
    P LS-00382: expression is of wrong type
    ORA-06550: line 1, column 7:
    PL/SQL: Statement ignored

    It doesn't look like your PL/SQL Function is returning a REF CURSOR to me. It looks like you are returning a PL/SQL Index-By table of Objects.
    Regards,
    Mark

  • Trying to get serial number for PSE12. Got redemption code. What's the next step?

    I am trying to get serial # for adobe Photoshop elements 12 I got the redemption code how do I get my serial # please help

    Redemption Code Help
    http://helpx.adobe.com/x-productkb/global/redemption-code-help.html

  • UCCX 7.0 Trying to Get Called Number step

    I'm trying to have my script recognize a specific called number and then based off that call number queue call at higher priority and send to agent.  I am in the debug state right now and it's blowing by IF statement for the called number.    What am I missing here?
    thanks
    Called Number = Get Call Contact Info
    IF (called_number==1234567) then
    True> Set Pri 7
    False>continue to queue call lower Pri

    are you in active or reactive debug mode?  if active, you cannot pull the get call contact info step, but I suspect you would have seen that.  so, I will assume you are in reactive.  but I want to make sure.
    I see you wrote out the script steps by hand, instead of a screenshot, or file upload, so this could easily be a typo, but your variable in the get call contact info step is:
    Called Number
    And your variable in the if step is:
    called_number
    They should be the same.
    Also, your if step should have the phone number literal in double quotes:
    "1234567"
    And not typed out like an integer:
    1234567
    But again, that could be a typo, and not really how your script is built.
    The logic looks good:
    Get Called NumberIf Called Number == Priority Number Then     Set PriorityElse     Do Nothing
    So I am only left to guess at the problem....do you use wild card triggers?  I.e., not 1234567, but 123XXXX?
    If you are using wild card triggers, then the Called Number would be the trigger:
    123XXXX
    And not the actual number dialed (you need to get the Dialed Number, which is at the bottom of the list):
    1234567
    If that is the case, then certainly:
    "123XXXX" != "1234567"
    And that would route your calls to the False branch of the If step.

  • Trying to get a movieclip to display on top of an externally loaded swf

    I am trying to ensure that a movieclip named "Incorrect"
    displays on top of a swf file that loads with the following:
    loadMovieNum("map.swf",1);
    I'm sure it's pretty simple, but I couldn't find any good
    reference to a movieclip loading on top of an external swf. I tried
    loading the map.swf into a placeholder movieclip and doing a
    swapDepth, but then the code within the map.swf would no longer
    function properly.
    thanks.

    you must load that movieclip into a _level greater than 1.
    there is no work-around if you load map.swf into _level1.
    you could load map.swf into a target movieclip and then use
    the swapDepths() method of movieclips to control the apparent depth
    of map.swf and your movieclip.

  • Trying to get an image to display

    Using the following query. I'm able to pull information from two tables and it's working
    <cfparam name="PageNum_rsGetProducts" default="1">
    <cfquery name="rsGetProducts" datasource="laurie">
    SELECT product_ID, product_MerchantProductID, product_Name, product_Description, product_ShortDescription, prdctImage_ProductID, prdctImage_FileName
    FROM dbo.tbl_products, dbo.tbl_prdtImages
    WHERE product_ID = prdctImage_ProductID
    ORDER BY product_Name
    </cfquery>
    <cfset MaxRows_rsGetProducts=10>
    <cfset StartRow_rsGetProducts=Min((PageNum_rsGetProducts-1)*MaxRows_rsGetProducts+1,Max(rsGetPro ducts.RecordCount,1))>
    <cfset EndRow_rsGetProducts=Min(StartRow_rsGetProducts+MaxRows_rsGetProducts-1,rsGetProducts.Rec ordCount)>
    <cfset TotalPages_rsGetProducts=Ceiling(rsGetProducts.RecordCount/MaxRows_rsGetProducts)>
    This is the HTML
    <body>
    <table border="1">
      <tr>
        <td>product_ID</td>
        <td>product_MerchantProductID</td>
        <td>product_Name</td>
        <td>product_Description</td>
        <td>product_ShortDescription</td>
        <td>pic </td>
      </tr>
      <cfoutput query="rsGetProducts" startRow="#StartRow_rsGetProducts#" maxRows="#MaxRows_rsGetProducts#">
        <tr>
          <td>#rsGetProducts.product_ID#</td>
          <td>#rsGetProducts.product_MerchantProductID#</td>
          <td>#rsGetProducts.product_Name#</td>
          <td>#rsGetProducts.product_Description#</td>
          <td>#rsGetProducts.product_ShortDescription#</td>
          <td><img src="#rsGetProducts.prdctImage_FileName#" /></td>
        </tr>
      </cfoutput>
    </table>
    </body>
    </html>
    However, the iamge doesn't display. All I get is the x. I went into DW and bound it to img.src and it's still not working - how can I get this to work

    Some things for you to check:
    does the image exist in the location referred to by the retrieved link?
    was the image created as RGB rather than CYMK?
    In general, you'll want all your images in a specific directory.

  • Re: Trying to get my number back since moving hous...

    have had a similar issue. I am waiting to be contacted about a renumber today since moving in December.
    I just got a repeat email to say to welcome on BT and about my move order from the 29th but no phone call to my mobile. I hoped the email meant something has been done but if I ring home it is still the old number. I had two order numbers & dates as the engineeer did not turn up the first time. The line was only installed on the 12th.
    This is what I was told on the chat last week.
    Ok all sorted out, they have had to put in what they called an injection order which will send a notice to the suppliers to close the order their end. We have been advised that this will happen on the 26th and you will then get a call anytime from 8-8 that day to get the renumber order done.
    I have a horrible feeling it is not getting done again. This is the 5th time and I am having to get the call via an app due to a signal deadzone in work.

    Hi mrsduff and welcome.
    I'm really sorry you're having problems with the renumber order. I'll be happy to help with this. Just drop me an email with your details. You'll get the 'contact us' link in my profile.
    Cheers
    David
    BTCare Community Mod
    If we have asked you to email us with your details, please make sure you are logged in to the forum, otherwise you will not be able to see our ‘Contact Us’ link within our profiles.
    We are sorry but we are unable to deal with service/account queries via the private message(PM) function so please don't PM your account info, we need to deal with this via our email account :-)

Maybe you are looking for

  • Material qty different from Sales Order to Invoice ex. qty 1 to qty 5

    Dear, Gurus I have 2 material types 98% are trading goods and 2%Service Material When I create invoice document with this order reference trading good materials are copying without a problem except the service material it is coming as qty 5 with the

  • Error while using utl_smtp,pls help

    CREATE OR REPLACE PROCEDURE send_mail (p_sender IN VARCHAR2, p_recipient IN VARCHAR2, p_message IN VARCHAR2) as l_mailhost VARCHAR2(255) := '10.16.56.30'; l_mail_conn utl_smtp.connection; BEGIN l_mail_conn := utl_smtp.open_connection(l_mailhost, 25);

  • Using Keynote with PPT

    I use PPT with embedded videos and when i pull them into Keynote on my iPad, my videos won't play.  Any help would be appreciated

  • Kernel panic at startup following updated to 10.6.8

    Following update via software update to 10.6.8, I had a kernel panic at start-up.  I was able to start up in "safe" mode.  I repaired permissions (numerous), verified the HD (appeared OK).  Rebooted in normal mode, and got kernel panic at start up. A

  • HTML content rising in front of MSO

    I have an HTML asset, and when I launch an MSO screen overlay, the HTML content is rising to the front, OVER my MSO, even though the MSO is on a layer above it. How do I remedy this?