Add JTable Row Headers At The End Of The Rows(At Right)?

hi all
i got this example for adding JTable Row Headers,but it adds the headers at the left(beginning of the row)
and i want to add the headers at the end of the row(at right),any ideas how to do that?
import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.AbstractListModel;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.ListCellRenderer;
import javax.swing.ListModel;
import javax.swing.UIManager;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.JTableHeader;
* @version 1.0 11/09/98
class RowHeaderRenderer extends JLabel implements ListCellRenderer {
  RowHeaderRenderer(JTable table) {
    JTableHeader header = table.getTableHeader();
    setOpaque(true);
    setBorder(UIManager.getBorder("TableHeader.cellBorder"));
    setHorizontalAlignment(CENTER);
    setForeground(header.getForeground());
    setBackground(header.getBackground());
    setFont(header.getFont());
  public Component getListCellRendererComponent(JList list, Object value,
      int index, boolean isSelected, boolean cellHasFocus) {
    setText((value == null) ? "" : value.toString());
    return this;
class RowHeaderExample extends JFrame {
  public RowHeaderExample() {
    super("Row Header Example");
    setSize(370, 150);
    ListModel lm = new AbstractListModel() {
      String headers[] = { "Row1", "Row2", "Row3", "Row4"};
      public int getSize() {
        return headers.length;
      public Object getElementAt(int index) {
        return headers[index];
    DefaultTableModel dm = new DefaultTableModel(lm.getSize(), 4);
    JTable table = new JTable(dm);
    table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
    table.setRowHeight(18);
    JList rowHeader = new JList(lm);
    rowHeader.setFixedCellWidth(50);
    rowHeader.setFixedCellHeight(18);
    rowHeader.setCellRenderer(new RowHeaderRenderer(table));
    JScrollPane scroll = new JScrollPane(table);
    scroll.setRowHeaderView(rowHeader);
    getContentPane().add(scroll, BorderLayout.CENTER);
  public static void main(String[] args) {
    RowHeaderExample frame = new RowHeaderExample();
    frame.addWindowListener(new WindowAdapter() {
      public void windowClosing(WindowEvent e) {
        System.exit(0);
    frame.setVisible(true);
}

fixed by:
list.setBackground(table.getTableHeader().getBackground());here's the full code:
import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.ComponentOrientation;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.DefaultListModel;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.ListCellRenderer;
import javax.swing.UIManager;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.JTableHeader;
* @version 1.0 11/09/98
class RowHeaderRenderer extends JLabel implements ListCellRenderer {
  JTable table;
  RowHeaderRenderer(JTable table) {
    this.table = table;
    JTableHeader header = table.getTableHeader();
    setOpaque(true);
    setBorder(UIManager.getBorder("TableHeader.cellBorder"));
    setHorizontalAlignment(CENTER);
    setForeground(header.getForeground());
    setBackground(header.getBackground());
    setFont(header.getFont());
  public Component getListCellRendererComponent(JList list, Object value,
      int index, boolean isSelected, boolean cellHasFocus) {
    list.setBackground(table.getTableHeader().getBackground());
    setText((value == null) ? "" : value.toString());
    return this;
class RowHeaderExample extends JFrame {
  public RowHeaderExample() {
    super("Row Header Example");
    setSize(370, 150);
    setLocationRelativeTo(null);
    DefaultListModel lstModel = new DefaultListModel();
    lstModel.addElement("Row 1");
    lstModel.addElement("Row 2");
    lstModel.addElement("Row 3");
    lstModel.addElement("Row 4");
    DefaultTableModel dm = new DefaultTableModel(lstModel.getSize(), 4);
    JTable table = new JTable(dm);
    table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
    table.setRowHeight(18);
    JList rowHeader = new JList(lstModel);
    rowHeader.setFixedCellWidth(50);
    rowHeader.setFixedCellHeight(18);
    rowHeader.setCellRenderer(new RowHeaderRenderer(table));
    JScrollPane scroll = new JScrollPane(table);
    scroll.setRowHeaderView(rowHeader);
    table.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
    scroll.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
    getContentPane().add(scroll, BorderLayout.CENTER);
  public static void main(String[] args) {
    RowHeaderExample frame = new RowHeaderExample();
    frame.addWindowListener(new WindowAdapter() {
      public void windowClosing(WindowEvent e) {
        System.exit(0);
    frame.setVisible(true);
}

Similar Messages

  • Need to add a new row at the end of the table

    Experts,
    working jdev 11.1.1.3.0
    i am adding row programetically, my requirement need to add the row at after last row.
    i tried different ways.
    Row newLastRow = getPWBBidLaneVO().last();
    int lastRowIndex = getPWBBidLaneVO().getRangeIndexOf(newLastRow);
    getPWBBidLaneVO().insertRowAtRangeIndex(lastRowIndex - 1,
    laneRow);
    this is giving --- java.lang.ArrayIndexOutOfBoundsException: 0
    and
    http://kohlivikram.blogspot.com/2008/10/add-new-row-in-adf-table-on-button.html --- its giving index out of bound because vo.getRangeSize() is 25. We set this value at vo for performance improment suggestions.
    is there a way to add a new row at the end of the table?

    Add this to the view row impl class
           public void insertRow(Row row) {
               //go to the end of Rowset if it has rows
               Row lastRow = this.last();
               if (lastRow !=null){
                    //insert new row at the end and make it current
                   int indx = this.getRangeIndexOf(lastRow)+1;
                   this.insertRowAtRangeIndex(indx,row);
                   this.setCurrentRow(row);
               }else { // empty Rowset
               super.insertRow(row);
               }

  • How to add an extra row at the end of the Grid?

    Hi gurus,
    I am getting result from the select query which has 4 columns.
    I got the requirement to display the sum of those columns as the last row.
    How can i add the another row at the end of the iGrid ?
    Data would look like
    Sno  Col1   Col2  Col3  Col4
    1         4       6      1       6
    2         5       8      0       8
    3         6       1      2       5
    Sum     15     14    3       19
    Do i have to add transformation to the sql query? or
    Can i add row to the display tempalate by accessing the Gridobject?
    Please help.
    Thanks
    Vansi
    Edited by: vamsi P on Feb 12, 2008 8:49 PM
    Edited by: vamsi P on Feb 12, 2008 8:49 PM

    Hi Vamsi,
    There are a few options ...
    1) The one suggested by Prasanna
    2) Loop through all rows via JavaScript and use the GridObject methods to set cell values and then perform an applet.refreshGrid( false )
    3) Apply an Inline transform
    4) Use a stored procedure to return the results and the totals as one recordset.
    The stored procedure would be the fastest for runtime.
    The Iniline XSL transform would be the second fastest.  If you specify the XSL in a generic way, you may even be able to reuse it in other scenarios.  If you hardcode the fields in the XSL, it would be a matter of simple code adjustment when you encounter a similar scenario.
    Hope this helps.
    Cheers,
    Jai.

  • Row getting added in the end of the scroll

    Hi -
    I am using a scroll area on a page on level 1. The issue iam encountering is that when ever i click the plus sign to add a second or third row (assume one record already exists in scroll 1) , the row gets added in the end of the scroll and also the fields are blank. However as delievered the new row should get added on the top of the scroll meaning 1 of 2 not 2 of 2, and also it should carry forward the values from the prior row. Please any suggestion or help is greatly appreciated.

    I figured it out. The reason it was happening was because, my scroll record had another key field after EFFDT and EFFSEQ, due to which the delivered copy forward logic for new rows in scroll did not work and the row was getting added in the end or after the first blank row always.

  • How to add a sub report at the end of the main report whilst grouped

    Hi!
    I have a main report that is grouped by the Customers name and then details of transactions they did with the company.
    I need to add a letter at the end of each group for each customer (With their name displayed in the letter). I tried adding a sub report in the report footer, but it only appears once at the end of the report, rather than at the end of each group for each customer.
    How can I achieve the desired result?
    Regards
    Vik

    Vik,
    You are on the right track with the sub-report.
    1. Create your letter in a separate report.
    2. Add the Letter Report to your original report as a sub report in the group footer.
    3. Set the report links on the "Group By" field.
    This will give you a letter record for each report record with the same grouping as the main report.
    Hope this helps,
    Jason

  • Osx 10.7.4   safari 6.0  when I add a new bookmark to the "bookmarks menu" it is added somewhere in the middle instead of at the end of the list.  this just started a few days ago after an update.  Has anyone else noticed this?.

    osx 10.7.4   safari 6.0  When I add a new bookmark to the "bookmarks menu" it is added somewhere in the middle instead of at the end of the list.  This just started a few days ago after an update.  Has anyone else noticed this?.

    Just for those who are interested, this is what cleared the "bookmark menu"  trbl I had.
    Open System Preferences > iCloud
    Deselect the box next to Bookmarks, then reselect it.
    Quit and relaunch Safari. Try a bookmark again.

  • The current version of Firefox moves the tabs. Now the focus moves off the end of the row. I think this runs counter to the point of having tabs, if you can only see one at a time. How do I fix this

    The tabs bar on 3.6 Firefox now focuses on the last tab in the row. This means that I can only effectively see one tab, unless I use the arrow button to scroll back through all the tabs. I am used to scrolling some, when there are a dozen tabs open, but How do I make the tab bar static, they way it used to be, so it stands still when I click on the last tab in the row.??

    Thanks for taking a stab at it: that didn't prove to be the problem. That option in the settings for tabbed browsing was not checked.
    I may be a bit behind the times: I am used to tabbed browsing showing all the tabs it possibly can, instead of just the last one. Sometimes it won't even show the last tab: I can have 15 tabs open, and not see a single tab. I've been confused by this into closing a window with lots of tabs open, because it looks like a single page-window.
    My main problem with the tab-bar flashing to the end of the row is that it means a great deal more mouse-clicking around to browse.
    I haven't tried installing the latest beta. Maybe that would fix the problem.
    Toddo

  • Automatically add a current date at the end of the comments

    Hi,
    I have a form on a table with 5 fields... on one the field I am asking my users to enter comments...
    I am looking for a functionality to automatically add a current date at the end of the comments, only when they are updated or newly filled in...
    Please advice how can I do it... I am anticipating some sort of a trigger on column (when the data is modified)...
    Thanks

    automatically add a current date at the end of the comments, only when they are updated or newly filled inDo you want to add the date to the page item itself and hence show it to the end user as and when its changed, thn
    Assuming comments item is named '*P1_COMMENTS* , add the following to the "execute on load"
    $('P1_COMMENTS').change( function(){
      var d = new Date();
      $s('P1_COMMENTS', $v('P1_COMMENTS')+ d.toUTCString() );
    });If its to be done only when updating ie in the PLSQL block
    UPDATE <table name>
    SET <comments _column> = (  SELECT DECODE(  NVL(<comments _column>,'')
                                                                          ,NVL(:P1_COMMENTS,'')
                                                                          ,<comments _column>
                                                                          ,:P1_COMMENTS||TOCHAR(SYSDATE,'DD-MON-YYY')
                                                  FROM DUAL
    WHERE <condition>

  • How to find end of the Page in Crystal ? or I need to add one Horizontal line at the end of the page.--- URGENT HELP NEEDED

    Hi friends,
    I need to add one horizontal line  for the detail section at the end of the page.
    I tried to put that line in page footer and i tried with Box also. Both are not properly working. Some space problem is coming.
    Is there any feature to find end of the Page.
    I want report format like this.
    set id  |  set name |  date  Name
      1         x           dddd   vijay
                            dddd   sarathi
                            dddd    reddy
    (End of the page)
    Thanks in advance...
    vijay.

    Do you know how many detail records are showing up per page?
    If you do - you could create a Details B section that is suppressed except for on Record N (where N is a counter, and N is the last Detail record that will show up on a page).
    The Page footer is indeed built so that it will be rendered at the bottom of your physical page of paper.

  • Does anyone know how to add a preface page at the beginning of the book in ibooks author once the book is written? No matter how I try to add a Preface page, it goes to the end of the book.

    Does anyone know how to add a preface page at the beginning of the book in ibooks author once the book is written? No matter how I try to add a Preface page, it goes to the end of the book.

    Thanks. I've tried this and apparently the template I'm using is one of those where it doesn't work. I've tried dragging it as well as cutting a pasting but it always travels back to the end of the book. Maybe I can try changing the template temporarily, move the preface page, and then convert back to the original template. I'll experiment a little.

  • How do I remove the (-signed) which Adobe adds to the end of the document name after having signed it?

    Hi there,
    How do I remove the (-signed) which Adobe adds to the end of the document name after having signed it?
    It is not convenient to remove it every time I sign a document. So, is there a way to turn this off?
    Thank you

    I think you cannot, because for many people it is so important to keep the unsigned document, and most do not realise this until it is too late.

  • BSP adds CR/LF marker at the end of the page even with compression options

    Hello!
    I'm creating normal BSP Page with Flow Logic and setting the contents myself:
    <%@page language="abap" %><%
      response->set_cdata( '-=-' ).
    %>
    The problem is that WebAS somehow always adds a CR/LF (new line) marker at the end of the page (even if I set compression option to "Remove leading and trailing spaces"). I also tried to set different mime-types.
    On the other side there is a BSP Application it00 (described here http://help.sap.com/saphelp_nw04/helpdata/en/eb/8c683c8de8a969e10000000a114084/content.htm ) that shows the uploaded file right.
    So I was trying to include that 'solution' setting OnInputProcessing event to this
    *         set response data to be the file content
              runtime->server->response->set_cdata( '!=!' ).
    *         set the mime-type and file size in the response
              runtime->server->response->set_header_field(
                name  = 'Content-Type'
                value = 'text/plain' ).
              runtime->server->response->set_header_field(
                name  = 'Content-Length'
                value = '3' ).
              navigation->response_complete( ).
    But nothing happens at all.
    Please, help me getting rid of these two annoying bytes ('CR/LF') at the end of page.

    Thank you, Cornelia!
    It works now.
    The following code is "must have"
    navigation->response_complete( ).

  • Putting buttons at the end of each row of a report

    Hi
    Was wondering if anyone new of a way to put buttons on the end of each row of a report. Basically i want a button and a LOV box next to the end of each row so that the user could set the value of the LOV box click the button and that would update just that row. Obviously i want to give them the option of batch processing it as well but for now i just want them to be able to update one row at a time.
    This does not nessacary need to be with a LOV box it could also work with radio buttons to specifiy the value to update.
    If anyone knows a way of doing this or any information where i can read about it then please let me know as i would be very interested.
    Or can you make report fields eidtable so that i can just run a massage update on the using all the values in the report?
    Thank you for your time
    Daniel Stead
    Message was edited by:
    Dan Stead

    No such luck a tabluar updat form shows all the rows for that table. I only want the user to be able to update their rows in the table.
    This is bascally what i want to do.
    I have two reports that only show records that are realted to the current user that is logged in.
    The first report shows all records in the table for the current user where the supervisor (the current user) type is set to confirmed.
    The second reprot shows all the records in the table for the current user where the supervisor (the current user) type is set to requested.
    That is what i have acheived so far.
    I want to be able to make the superviosr type in the second report editable with a list of values requested, rejected and confirmed. The user can then select what he would like the type to be for the specific record in the report and then press a button that updates all the reocrds (or a button at the end of each row that updates each row). If the row is confirmed it moves to the first report, if it is still requested it stays in the second report and if it is set to rejected then it will be in neither report.
    Therefore my question is if i make the supervisor type eidtable how can i link it to the id of that row so that it updates it?
    If this is not clear please state to me which part i have not made clear.
    Thank you for your help.
    Daniel Stead

  • Cant add to the end of the array list

    Hey everyone
             for(String word : dictionary){
                 if(word.equalsIgnoreCase(newWord) == false && word.compareToIgnoreCase(newWord) >= 0){
                     dictionary.add(dictionary.indexOf(word), newWord);
                     save();
                     break;
        }i am struggling to see the bug in my code, why will it not allow me to enter anything to the end of the array list, but anywehere other is fine?
    thanks very much

    Try posting a SSCCEE. Your code could be better written:
    1. You are using the enhanced for loop, then you have to turn around and use indexOf to see where you are in the list. Think about that.
    2. Are you sure you have to use both equalsIgnoreCase and compareIgnoreCase to get the result you need?

  • I want my new tabs to open at the end of the row of tabs, how do I do that?

    When I open a new tab, I would like it to open at the end of the row of tabs, not next to the tab I'm on now. I'm used to it opening on the end like it did in older versions of Firefox. I'm sure this is an easy fix but I can't find anything in options and I'm getting frustrated.
    Thanks!

    Hello callagalla, go to [http://kb.mozillazine.org/About:config about:config] find(or copied/paste from there) '''browser.tabs.insertRelatedAfterCurrent''' and double-click on it to make it FALSE.
    thank you

Maybe you are looking for

  • Unable to scan doc's using my HP M1536 dnf

    I'm facing some new issue using HP laserjet M1536dnf printer & Scanner, in my office number of systems are there, i can able to give print and scan from all systems accept one system i tried so many settings and troubleshoot's but no use its not work

  • Verity issue after purging a collection

    All, I have recently discovered an issue with the way verity provides suggestions when returning search results. I have created a verity collection using verity spider. i have registerd this collection in CFAdmin. I have successfully searched against

  • Having problem while uploading the data.

    Hi All, i am facing some problem when trying to upload csv file in the database. ERROR: "SQL*Loader-704: Internal error: ulconnect: OCIServerAttach [0] ORA-12560: TNS:protocol adapter error". have anybody aware of this kind of problem or having knowl

  • My apps have been downloading for 2 days now is this normal

    ive downloade some apps but they have been "waiting"for 3 days now is this normal ive tried to delete and reinstall also just taking forever

  • How do I get iTunes to work on an old laptop with only 300mb of ram

    I have an old Compaq pressario with just over 300mb of ram that i want to run iTunes on. It has a slow processor which does not meet the recommendations but I just wanted the bare functionality to run and setup an iPhone for my mother to use. It is a