Sort rows in JTable except the last row

Hi All,
I have a JTable, which contains columns with numbers. The last row contains column sums.
I want to be able to sort rows, but the last row with sums must remain motionless.
Does anyone know the solution of this problem?
Thanks in advance.

These two posts are my example. It works pretty good but there is one significant niggle - when moving a column the 'total' table does not move smoothly but it does move. I look forward to 'camickr' reducing this to about 1 line.
Part A.
import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Font;
import java.text.DecimalFormat;
import java.util.Comparator;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.TableColumnModelEvent;
import javax.swing.event.TableColumnModelListener;
import javax.swing.table.AbstractTableModel;
import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.JTableHeader;
import javax.swing.table.TableColumnModel;
import javax.swing.table.TableModel;
import javax.swing.table.TableRowSorter;
public class Sabre20090331
    static private class TotalizingTableComponent extends JScrollPane
        private TotalizingTableComponent(final TableModel tableModel)
            final SecondaryTableModel secondaryTableModel = new SecondaryTableModel(tableModel);
            final JTable secondaryTable = new JTable(secondaryTableModel);
            for (int i = 1; i < secondaryTableModel.getColumnCount(); i++)
                secondaryTable.getColumnModel().getColumn(i).setCellRenderer(new NumberCellRenderer());
            secondaryTable.getColumnModel().getColumn(0).setCellRenderer(new TitleCellRenderer());
            final TableColumnModel secondaryTableColumnModel = secondaryTable.getColumnModel();
            secondaryTable.setRowSelectionAllowed(false);
            final JTable primaryTable = new JTable(tableModel);
            for (int i = 1; i < tableModel.getColumnCount(); i++)
                primaryTable.getColumnModel().getColumn(i).setCellRenderer(new NumberCellRenderer());
            final TableRowSorter<TableModel> sorter = new TableRowSorter<TableModel>(tableModel);
            final DoubleComparator doubleComparator = new DoubleComparator();
            for (int i = 1; i < tableModel.getColumnCount(); i++)
                sorter.setComparator(i, doubleComparator);
            primaryTable.setRowSorter(sorter);
            primaryTable.getColumnModel().addColumnModelListener(new TableColumnModelListener()
                @Override
                public void columnAdded(TableColumnModelEvent e)
                    // System.out.println("columnAdded()" + e);
                @Override
                public void columnRemoved(TableColumnModelEvent e)
                    // System.out.println("columnRemoved()" + e);
                @Override
                public void columnMoved(TableColumnModelEvent e)
                    //System.out.println("columnMoved()" + e);
                    secondaryTableColumnModel.moveColumn(e.getFromIndex(), e.getToIndex());
                @Override
                public void columnMarginChanged(ChangeEvent e)
                    //System.out.println("columnMarginChanged()" + e);
                    final TableColumnModel cm = (TableColumnModel) e.getSource();
                    for (int i = 0; i < cm.getColumnCount(); i++)
                        secondaryTableColumnModel.getColumn(i).setPreferredWidth(cm.getColumn(i).getWidth());
                @Override
                public void columnSelectionChanged(ListSelectionEvent e)
                    //System.out.println("columnSelectionChanged()" + e);
            final JTableHeader primaryHeader = primaryTable.getTableHeader();
            JPanel inner = new JPanel(new BorderLayout());
            this.setColumnHeaderView(primaryHeader);
            this.setViewportView(inner);
            inner.add(primaryTable, BorderLayout.NORTH);
            inner.add(secondaryTable, BorderLayout.CENTER);
        public static void main(String[] args)
            final JFrame frame = new JFrame("Totalizing JTable Example");
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            final TableModel tableModel = new PrimaryTableModel();
            frame.setContentPane(new TotalizingTableComponent(tableModel));
            frame.pack();
            frame.setVisible(true);
}Edited by: sabre150 on Apr 1, 2009 9:21 AM
Changed the layout of the inner panel so that the secondary table is now in the CENTER. This stops the secondary table becoming detached from the primary when one expands the frame beyond the prefferred size.

Similar Messages

  • Page totals not printing on any pages except the last

    How do you get page totals to display one each page and "float" with the output? I created a summary object for the column with reset at page and put it in a frame that is displayed on all pages. There is, of course, a repeating group above it. But the repeating group clobbers the page totals on all except the last page. Shouldn't there be an implicit anchor that prevents this? that's what the Oracle documentation says anyway. This is probably real simple, but I find nothing in any documentation, white papers, or anything.
    Will somebody please, please help me?

    Hi,
    Step 1: Select the parent frame of the summary column.
    Step 2: Open properties of that frame
    Step 3: Set the property "Print Object On" to "All Pages" value.
    (Default value for this property is "Last Page"
    Regards,
    Sailaja

  • What is wrong? The "show my windows and tabs from last time" has not been working these past two or three days. It was fine before. Ive changed nothing except the last update from you. Thank you.

    What is wrong? The "show my windows and tabs from last time" has not been working these past two or three days. It was fine before. Ive changed nothing except the last update from you. Thank you.

    Make sure that you do not use "Clear Recent History" to clear the "Browsing History" when Firefox is closed because that prevails and prevents Firefox from opening tabs from the previous session.
    * https://support.mozilla.com/kb/Clear+Recent+History
    It is possible that there is a problem with the files sessionstore.js and sessionstore.bak in the Firefox Profile Folder.
    Delete the files sessionstore.js and sessionstore.bak in the Firefox Profile Folder.
    * Help > Troubleshooting Information > Profile Directory: Open Containing Folder
    * http://kb.mozillazine.org/Profile_folder_-_Firefox
    * http://kb.mozillazine.org/Session_Restore
    * http://kb.mozillazine.org/sessionstore.js
    If you use cleanup software like CCleaner then make sure that Session is unchecked in the settings for the Firefox application.

  • How do I sort my address book by the last name, not the first name

    AS I created my address book the names were added randomly to the address book. When I print out the address book the names come up with first name, Last name (all in random order alphabetically). I would like them to come up with Last name, first name, email address in alphabetic order by the Last Name. How do I get them sorted corretly??

    Enable the menu in the Address Book. Then look at the options under View and Sort By.
    More here on sorting: http://www.ramsden.org.uk/8_How_to_sort.html
    And about menus here: http://chrisramsden.vfast.co.uk/13_Menus_in_Thunderbird.html

  • TS1424 Needing info on an album I just purchased. Every song on the album seemed to download except the last. Then when I went back to play them  it seemed to only download  2 minutes of each tune

    Needing info on an album I purchased. Thought every song had downloaded . But the last song didn't download and then on the playback every song only had  2 minutes of play on it .It's like they are only partially downloaded. Thanks for any comments!

    If your country's iTunes Store allows you to redownload purchased tracks, I'd delete your current copies of the dodgy tracks and try redownloading fresh copies. For instructions, see the following document:
    Downloading past purchases from the App Store, iBookstore, and iTunes Store
    Otherwise, I'd report the problem to the iTunes Store.
    Log in to the Store. Click on "Account" in your Quick Links. When you're in your Account information screen, go down to Purchase History and click "See all".
    Find the items that are not playing properly. If you can't see "Report a Problem" next to the items, click the "Report a problem" button. Now click the "Report a Problem" links next to the items.

  • I can open all of my docs in Pages except for the last one I was working on for some reason. Does anyone know what might be the problem?

    I can open all my docs in Pages except the last one I was working on. Does anyone know what might be the problem?

    The document might be corrupt. If you worked on this particular document at all in the iWorks in iCloud.com beta, that may have caused a problem. If you don't know what I'm talking about, you can rule that out as a possibility.
    In any event, you could try opening the documents in iCloud.com using your computer, and see if you can download it to the computer, edit it there and then upload it again.

  • Using an index to access the last n values of a certain combination

    I have a large table of the following form:
    Name Typ
    ID NUMBER
    M_DATE DATE
    M_LOC NUMBER
    M_ARTICLE VARCHAR2(30)
    M_TYPE VARCHAR2(30)
    M_MEASURE VARCHAR2(50)
    VALUE NUMBER
    In this table there is only a small number of different locations, articles, types and maesures but a large number of m_date values.
    I want to access the last 10 values for a certain combination of locations, articles, types and measures.
    I have an index
    create index i_res_2 on results (m_loc, m_article, m_type, m_measure, m_date);
    In my opinion it should be possible to access the last 10 values directly by this index, but
    when I do my select in the following way it seems to me that first all datasets with the same
    locations, articles, types and maesures are selected, then sorted by date and then the last 10
    dates are selected. As those datasets are spread over the whole table it needs a higher number
    of physical reads. Is there a way to have an index on m_date and an other form of this query
    that selects the requested values with less phyical reads? (Database version is 10.2)
    SQL> select
    2 id,
    3 m_date,
    4 value
    5 from (
    6 select
    7 id,
    8 m_date,
    9 value,
    10 rank() over (order by m_date desc) r
    11 from results
    12 where m_loc = '14001'
    13 and m_article = '11211-00-00'
    14 and m_type = '0002'
    15 and m_measure = '032')
    16 where r <= 10
    17 order by m_date asc;
    ID M_DATE Value
    3931958 05.03.10 69.00
    3931960 05.03.10 69.00
    3905712 10.03.10 68.60
    3999535 10.03.10 69.70
    3985125 11.03.10 69.40
    3957851 11.03.10 69.60
    3949799 21.03.10 68.70
    4017369 21.03.10 69.00
    3951981 22.03.10 68.80
    3983554 22.03.10 68.80
    Abgelaufen: 00:00:03.00
    | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
    | 0 | SELECT STATEMENT | | 1 | 48 | 6 (34)| 00:00:01 |
    | 1 | SORT ORDER BY | | 1 | 48 | 6 (34)| 00:00:01 |
    |* 2 | VIEW | | 1 | 48 | 5 (20)| 00:00:01 |
    |* 3 | WINDOW SORT PUSHED RANK | | 1 | 39 | 5 (20)| 00:00:01 |
    | 4 | TABLE ACCESS BY INDEX ROWID| RESULTS | 1 | 39 | 4 (0)| 00:00:01 |
    |* 5 | INDEX RANGE SCAN | I_RES_2 | 1 | | 3 (0)| 00:00:01 |
    Predicate Information (identified by operation id):
    2 - filter("R"<=10)
    3 - filter(RANK() OVER ( ORDER BY INTERNAL_FUNCTION("M_DATE") DESC )<=10)
    5 - access("M_LOC"=14001 AND "M_ARTICLE"='11211-00-00' AND "M_TYPE"='0002' AND
    "M_MEASURE"='032')
    Statistiken
    1 recursive calls
    0 db block gets
    547 consistent gets
    474 physical reads
    0 redo size
    766 bytes sent via SQL*Net to client
    380 bytes received via SQL*Net from client
    2 SQL*Net roundtrips to/from client
    2 sorts (memory)
    0 sorts (disk)
    10 rows processed

    I found a solution, which is much better in terms of physical reads and consistent gets even if the optimizer calculates higher costs. But I still think, that there should be an easier way to do this:
    SQL> select
    2 id, m_date, value from results
    3 where
    4 (m_loc, m_article, m_type, m_measure, m_date)
    5 in
    6 (select m_loc, m_article, m_type, m_measure, m_date
    7 from (
    8 select /*+ first_rows(10) */ m_loc, m_article, m_type, m_measure, m_date
    9 from results
    10 where m_loc = '14001'
    11 and m_article = '11370-00-00'
    12 and m_type = '0002'
    13 and m_measure = '032'
    14 order by m_loc,m_article,m_type,m_measure,m_date desc
    15 ) where rownum < 10);
    ID M_DATE VALUE
    2495995 01.02.09 70,4
    2457657 19.01.09 66,9
    2556262 13.02.09 67,4
    2496232 01.02.09 67,6
    2465051 20.01.09 67
    2454994 19.01.09 67,4
    2545951 13.02.09 67,4
    2502216 01.02.09 67,5
    2497533 01.02.09 67,2
    9 Zeilen ausgewählt.
    Ausführungsplan
    Plan hash value: 3924867000
    | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
    | 0 | SELECT STATEMENT | | 1 | 122 | 8 (25)| 00:00:01 |
    | 1 | TABLE ACCESS BY INDEX ROWID| RESULTS | 1 | 39 | 3 (0)| 00:00:01 |
    | 2 | NESTED LOOPS | | 1 | 122 | 8 (25)| 00:00:01 |
    | 3 | VIEW | VW_NSO_1 | 1 | 83 | 4 (25)| 00:00:01 |
    | 4 | HASH UNIQUE | | 1 | 31 | | |
    |* 5 | COUNT STOPKEY | | | | | |
    | 6 | VIEW | | 1 | 31 | 4 (25)| 00:00:01 |
    |* 7 | SORT ORDER BY STOPKEY| | 1 | 31 | 4 (25)| 00:00:01 |
    |* 8 | INDEX RANGE SCAN | I_RES_2 | 1 | 31 | 3 (0)| 00:00:01 |
    |* 9 | INDEX RANGE SCAN | I_RES_2 | 1 | | 2 (0)| 00:00:01 |
    Predicate Information (identified by operation id):
    5 - filter(ROWNUM<10)
    7 - filter(ROWNUM<10)
    8 - access("M_LOC"=14001 AND "M_ARTICLE"='11370-00-00' AND "M_TYPE"='0002'
    AND "M_MEASURE"='032')
    9 - access("M_LOC"="$nso_col_1" AND "M_ARTICLE"="$nso_col_2" AND
    "M_TYPE"="$nso_col_3" AND "M_MEASURE"="$nso_col_4" AND "M_DATE"="$nso_col_5")
    Statistiken
    1 recursive calls
    0 db block gets
    36 consistent gets
    14 physical reads
    0 redo size
    748 bytes sent via SQL*Net to client
    381 bytes received via SQL*Net from client
    2 SQL*Net roundtrips to/from client
    1 sorts (memory)
    0 sorts (disk)
    9 rows processed

  • I have multiple imap accounts on thunderbird, but the last two accounts will not show messages in the inbox.

    I have 7 imap accounts some with several subscribed folders. One is a gmail account. The others are from a personal .com. Everything works fine, including the gmail, except the last two accounts added will not sync the inboxes. The sent boxes sync fine, but I see no messages in the inboxes of just the last two accounts added. I know the imap server is working properly as the messages received to these accounts can be viewed via webmail, and the inboxes sync just fine on my email on my phone. I have been over and over all the settings from account to account. What am I missing. Please help.
    Thank you.

    Security Software and Related Troubles
    http://support.apple.com/kb/TS3125          Basic Troubleshooting
    http://support.apple.com/kb/TS3297          Advance Troubleshooting
    http://support.apple.com/kb/ts1629          Ports List
    Basics
    Check correct date, time, and timezone.
    Log in as administrative user account
    Verifiy iTunes updated
    Update Operating System “OS” (Ms Windows, Mac OSX)
    Update Modem / Router firmware
    Update security software (Antivirus, Firewall)
    Remove Outdated Security Software (Always restart afterwards)
    Advanced
    Remove Mobile Software not used anymore
    (Motorola, Android, Nokia, Sony, Blackberry)
    Add Apple programs to firewall permissions
    Allow Ports 80, 443, 3689, 5297, 5298, 5353, 8000-8999, and 42000-42999
    Permit Domains - apple.com , edgesuite.net , mzstatic.com
    Disable Security Software
    Remove Security Software (restart!)
    Delete “Hosts” file and restart, or edit and save.
    Check Browser Settings: Use SSL3, TLS1, Auto Detect, No Proxy Settings
    Reinstall itunes FOLLOWING ARTICLE while all security off / disabled or completely removed.
    http://support.apple.com/kb/HT1923
    http://support.apple.com/kb/HT1925

  • Page number shows up on the last page only

    Hello,
    I have a report that includs 5 sub reports. After modifing the order of the sub reports per user requests, I lost  the page number (Page N of M ) on each page except the last page.  The same thing happened before on a cross-tab report without any sub report in it.
    Please advise me !
    Thanks a lot,
    Lin

    Hello,
    Thank you for your replay. Actually the page number is on the Page Foot. Is any one has the same problem ?
    Your input is grate appreciated !
    Lin

  • How to write the last step into the temporary XML file?

    Hi all,
    I'm running a sequence & writing the results of each step to a report file.
    When reviewing the report On-The-Fly I see azll the steps (including the last one), but in the temporary report file (ends with _00001.xml) has all the steps except the last one.
    anyone has an idea how can I "force" TestStand to write all the buffer to the file?
    thanks,
    Ido

    IdoZe,
    I was able to replicate your behavior you were seeing and spoke with our R&D team on this. On-the-fly reporting is not guaranteed to write every step, this would cause way too much writing to disk and would cause performance problems because of this. It instead writes according to when the DLL is set to write based on timers and other pieces of dll code.
    With what you are trying to do, it seems you are approaching it incorrectly. First of all, you are accessing and editing a temporary report, which is not recommended. Second, there are many better ways to do this instead of just adding a step to your main or even clean-up of your sequence. You could A) Override the PostUUT or PostUUTLoop callbacks or B) create a top level sequence that makes a sequence call to your sequence you want the report for. In the properties you would spawn a new execution for that sequence after the sequence call, you could wait for the sequence to complete and then read the XML in another step.
    You should always use the final report for this though, because editing the temporary report is a bad idea.
    Another idea is to modify the report generation to write the report correctly the first time you read it. It all depends on exactly what you are trying to do, but I would strongly suggest this last option if possible as it does not involve editing the report after it is written, which defeats the report generation's purpose.
    Brandon Vasquez | Software Engineer | Integration Services | National Instruments

  • WMI filter query of the last GPO in an OU fails

    Hi,
    I've noticed an interesting issue:
    Server 2012 R2, Windows 7. GPO's. WMI Filters.
    I've linked some GPOs to a specific OU (which exclusively contains users). For example, there are three objects which configure Word, Excel and PowerPoint 2010. I've created a WMI Filter to query wether Office 2010 is installed and mapped it to these
    GPO's (I'm using the same filter for all these Office 2010 GPOs)
    The problem: On my test client (Windows 7 Pro x64), all these Office GPOs are getting applied (which means that the Office 2010 WMI query returns 'true') except the last one (regarding the
    link order). This last object is not applying because the WMI query returns 'false'.
    Here's an example. My test user is located in an OU called 'TestOU' on which the mentioned Office 2010 GPOs are linked to. The link order of the GPOs is as follows: 1. Word 2010, 2. Excel 2010, 3. PowerPoint 2010.
    In this case, the GPO called 'PowerPoint 2010' is not getting applied; the WMI filter returns 'false'. all other GPOs (using the same WMI filter) are getting applied. If i move the GPO named 'Excel 2010' to the end of the link order (1. Word 2010, 2. PowerPoint
    2010, 3. Excel 2010), it's the Excel GPO which is not getting applied.
    Any ideas?
    Best regards,
    eightcore
    EDIT: After logging off and logging in again (client-side), the "last" GPO is getting applied. But that's not a solution in my point of view. My goal is to get all things done right after the first logon.

    Hi eightcore,
    Based on my knowledge, when a GPO that is linked to a WMI filter is applied on the target computer, the filter is evaluated on the target computer. If the WMI filter evaluates to false, the GPO is not applied (except if the client computer is running Windows 2000,
    in which case the filter is ignored and the GPO is always applied).And in the same OU, the link order can tell us the applying order, and GPOs apply from the highest number to the lowest number.
    According to your description, the GPO which has the highest link order number will not apply. To do further trooubleshooting, please test the following situation:
    If delete the WMI filtering of the GPO which has the highest link order number, could the GPO apply sucessfully?
    If there are only two GPOs, could the two GPOs applu sucessfully?
    It would be helpful for future troubleshooting if you can provide the detailed information of the three GPOs.
    Regards,
    Lany Zhang

  • JTable cell Render on the last row column one help please

    Hi All
    I am hoping that someone will be able to help me with this....
    I want to render the last row and column one of the table with this render
    thanks for any help
    Craig
        public class MyRenderer2 extends DefaultTableCellRenderer {
            public Component getTableCellRendererComponent(JTable table,
                    Object value,
                    boolean isSelected, boolean hasFocus,
                    int row, int column) {
                ImageIcon icon = new ImageIcon(image_pics.SMALL_BLUE);
                setIcon(icon);
                return this;
        }

    it still renders every row
    any Ideas ??
    I just want the last row column 0 to be rendered
    I a call a method set table
    then I call for the data
    //TableModel
        public void setClientTableModel() {
            clientModel = new DefaultTableModel(coloumHeaderObject, 0) {
                public boolean isCellEditable(int row, int column) {
                    return false;
            TableSorter sorter = new TableSorter(clientModel); //ADDED THIS
            sorter.setTableHeader(phoneList.getTableHeader()); //ADDED THIS
            phoneList.setModel(sorter);
           // phoneList.setTableHeader(null);
            setTable();
            revalidate();
        public void setTable() {
          // phoneList.getColumnModel().getColumn(0).setCellRenderer(new MyRenderer());
            phoneList.getColumnModel().getColumn(1).setCellRenderer(new MyRenderer1());
            phoneList.getColumnModel().getColumn(4).setCellRenderer(new MyRenderer2());
            phoneList.getColumnModel().getColumn(0).setMinWidth(20);
            phoneList.getColumnModel().getColumn(0).setMaxWidth(20);
            phoneList.getColumnModel().getColumn(0).setPreferredWidth(20);
            phoneList.getColumnModel().getColumn(1).setMinWidth(20);
            phoneList.getColumnModel().getColumn(1).setMaxWidth(20);
            phoneList.getColumnModel().getColumn(1).setPreferredWidth(20);
            phoneList.getColumnModel().getColumn(2).setMinWidth(80);
            phoneList.getColumnModel().getColumn(2).setMaxWidth(80);
            phoneList.getColumnModel().getColumn(2).setPreferredWidth(80);
            phoneList.getColumnModel().getColumn(3).setMinWidth(150);
            phoneList.getColumnModel().getColumn(3).setMaxWidth(150);
            phoneList.getColumnModel().getColumn(3).setPreferredWidth(150);
            phoneList.getColumnModel().getColumn(4).setMinWidth(20);
            phoneList.getColumnModel().getColumn(4).setMaxWidth(20);
            phoneList.getColumnModel().getColumn(4).setPreferredWidth(20);
            phoneList.setOpaque(false);
            phoneList.setGridColor(Color.lightGray);
            phoneList.setRowHeight(18);
            phoneList.setShowVerticalLines(false);
            phoneList.setIntercellSpacing(new Dimension(0, 0));
            phoneList.setFont(new java.awt.Font("Lucida Grande", 0, 11));
            phoneList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
            if (ALLOW_COLUMN_SELECTION) { // false by default
                if (ALLOW_ROW_SELECTION) {
                    phoneList.setCellSelectionEnabled(true);
                phoneList.setColumnSelectionAllowed(true);
                ListSelectionModel colSM = phoneList.getColumnModel().getSelectionModel();
                colSM.addListSelectionListener(new ListSelectionListener() {
                    public void valueChanged(ListSelectionEvent e) {
                        if (e.getValueIsAdjusting())return;
                        ListSelectionModel lsm = (ListSelectionModel) e.getSource();
                        int row = phoneList.getSelectedRow(), col = 3;
                        int rowID = phoneList.getSelectedRow(), colID = 5;
                        if (lsm.isSelectionEmpty()) {
                        } else {
                            int selectedCol = lsm.getMinSelectionIndex();
                            if (selectedCol == 4) {
                                phoneNumber = (String) phoneList.getValueAt(row, col).toString();
                                main.setPhoneNumber(phoneNumber);
                                main.openLargePhone();
                                lsm.clearSelection();
                            if (selectedCol == 5) {
                                ID = (String) phoneList.getValueAt(row, col).toString();
                             //   main.setID(ID);
                              //  main.deleteContact();
                                lsm.clearSelection();
    //set table data
        public void setTest() {
            setClientTableModel();
            Object[] data = {" ", " ", "Work", "03 9841-8247", " "};
            clientModel.addRow(data);
            Object[] data1 = {" ", " ", "Fax", "03 9842-0360", " "};
            clientModel.addRow(data1);
            phoneList.getColumnModel().getColumn(0).setCellRenderer(new MyRenderer());
        }

  • Cant get the last row in jtable

    Hello all.
    I am trying to get the last row from the table but get "" from it.
    my table has 6 rows and i can get all rows right but the last line I have a problem.
            //creating the table
        for (i=0;i<this.rows;i++)
         model.insertRow(i,new Object[]{"input Y1:",""});
                for ( i=i;i<this.Amount+this.rows;i++)
         model.insertRow(i,new Object[]{"input Amount:",""});
    //end of creatingthis code creats the table that i need and its works right.
    for(i=0;i<rows;i++){
                  fObj.fullData[i] = Double.valueOf(GetData(table, 1, i).toString()).doubleValue();
            int j=0;
            String s=GetData(table, 1, 4).toString();
            //the problem line
            String s1=GetData(table, 1, 5).toString();
        public Object GetData(JTable table, int col_index, int row_index){
        return table.getModel().getValueAt(row_index, col_index);
      }this line i get ""
    String s1=GetData(table, 1, 5).toString();
    Edited by: vitaly87 on 00:41 08/04/2011

    vitaly87 wrote:
    Hello all.
    I am trying to get the last row from the table but get "" from it.
    my table has 6 rows and i can get all rows right but the last line I have a problem.
    this line i get ""
    String s1=GetData(table, 1, 5).toString();Looks right to me, given that your insert ismodel.insertRow(i,new Object[]{"input Amount:",""});(Hint: indexes start at *0* ).
    If it hadn't found the row, I expect you would have got an Exception
    Winston

  • How to test to see if the cursor is on the last row in a jTable?

    I like to know how to test the cursor position in jTable.

    From the many topics you post here, I can see that you are thinking in the wrong terms.
    Although it's possible, you should not test if the current row is the last one in a JTable. Instead you should test whether or not the current row is the last one in a VO instance, to which any particular JTable's model is bound.
    So, please read the API documentation for oracle.jbo.ViewObject and oracle.jbo.server.ViewObjectImpl.

  • Add rows and sort JTable in the same program

    I would like to have a button to add rows to the JTable, but would also like to sort the data within the columns. This program can sort the data prior to clicking the 'add row' button. After I click the button, there is no new row, and I lose the ability to sort the column. Do you have any tips or advice as to what I can do to fix my program? Is it because I have to have the final code for SortFilterModel to work?
    Thanks
    import java.awt.*;
    import java.awt.event.*;
    import java.util.*;
    import javax.swing.*;
    import javax.swing.event.*;
    import javax.swing.table.*;
    public class TableRowColumn extends JFrame
         private final static String LETTERS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
         JTable table;
         DefaultTableModel model;
         JPanel buttonPanel;
         JButton button;
         public TableRowColumn()
              Object[][] data = {
                        {"6", "K"},
                        {"5", "A"},
                        {"1", "Z"}
              String[] columnNames = {
                    "Number",
                    "Letter"
              model = new DefaultTableModel(data, columnNames);
                    //comment out this SortFilterModel line
                    final SortFilterModel sorter = new SortFilterModel(model);
                    //Change sorter to model
              table = new JTable(sorter);
              table.putClientProperty("terminateEditOnFocusLost", Boolean.TRUE);
              //  Add table and a Button panel to the frame
              JScrollPane scrollPane = new JScrollPane( table );
              getContentPane().add( scrollPane );
              buttonPanel = new JPanel();
              getContentPane().add( buttonPanel, BorderLayout.SOUTH );
              button = new JButton( "Add Row" );
              buttonPanel.add( button );
              button.addActionListener( new ActionListener()
                   public void actionPerformed(ActionEvent e)
                        model.addRow( createRow() );
                        int row = table.getRowCount() - 1;
                        table.changeSelection(row, row, false, false);
                        table.requestFocusInWindow();
                 //Set up double click handler for column headers and sort
                 table.getTableHeader().addMouseListener(new MouseAdapter(){
                        public void mouseClicked(MouseEvent event)
                          //check for click
                          if (event.getClickCount() < 2) return;
                       //find column of click and
                       int tableColumn = table.columnAtPoint(event.getPoint());
                       //translate to table model index and sort
                       int modelColumn = table.convertColumnIndexToModel(tableColumn);
                       sorter.sort(modelColumn);
         private Object[] createRow()
              Object[] newRow = new Object[2];
              int row = table.getRowCount() + 1;
              newRow[0] = Integer.toString( row );
              newRow[1] = LETTERS.substring(row-1, row);
              return newRow;
         public static void main(String[] args)
              TableRowColumn frame = new TableRowColumn();
              frame.setDefaultCloseOperation( EXIT_ON_CLOSE );
              frame.pack();
              frame.setVisible(true);
    }

    I attempted to modify the code in the correct way, but I ran into a problem near the bottom with the model.addRow(rowData); line. It has an error saying it can't find the addRow method. If I take away the model part, it will compile, but it will cause an infinite loop when I push the 'Add Row' button within the program. I didn't expect that to work, and I think it isn't calling the right model.
    I am aware that my code organization and design skills are not very good. I am a fan of basic assembly and low-level hardware languages for the most part.
    Thanks for your advice so far, it has been helpful.
    import java.awt.*;
    import java.awt.event.*;
    import java.util.*;
    import javax.swing.*;
    import javax.swing.event.*;
    import javax.swing.table.*;
    public class TableRowColumn extends JFrame
         private final static String LETTERS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
         JTable table;
         public DefaultTableModel model;
         JPanel buttonPanel;
         JButton button;
         public TableRowColumn()
              Object[][] data = {
                        {"9", "C"},
                        {"5", "A"},
                        {"3", "B"}
              String[] columnNames = {
                    "Number",
                    "Letter"
              model = new DefaultTableModel(data, columnNames);
                    //comment out this SortFilterModel line
                    final SortFilterModel sorter = new SortFilterModel(model);
                    //Change sorter to model
              table = new JTable(sorter);
              table.putClientProperty("terminateEditOnFocusLost", Boolean.TRUE);
              //  Add table and a Button panel to the frame
              JScrollPane scrollPane = new JScrollPane( table );
              getContentPane().add( scrollPane );
              buttonPanel = new JPanel();
              getContentPane().add( buttonPanel, BorderLayout.SOUTH );
              button = new JButton( "Add Row" );
              buttonPanel.add( button );
              button.addActionListener( new ActionListener()
                   public void actionPerformed(ActionEvent e)
                        sorter.addRow( createRow() );
                        int row = table.getRowCount() - 1;
                        table.changeSelection(row, row, false, false);
                        table.requestFocusInWindow();
                 //Set up double click handler for column headers and sort
                 table.getTableHeader().addMouseListener(new MouseAdapter(){
                        public void mouseClicked(MouseEvent event)
                          //check for click
                          if (event.getClickCount() < 2) return;
                       //find column of click and
                       int tableColumn = table.columnAtPoint(event.getPoint());
                       //translate to table model index and sort
                       int modelColumn = table.convertColumnIndexToModel(tableColumn);
                       sorter.sort(modelColumn);
         private Object[] createRow()
              Object[] newRow = new Object[2];
              int row = table.getRowCount() + 1;
              newRow[0] = Integer.toString( row );
              newRow[1] = LETTERS.substring(row-1, row);
              return newRow;
         public static void main(String[] args)
              TableRowColumn frame = new TableRowColumn();
              frame.setDefaultCloseOperation( EXIT_ON_CLOSE );
              frame.pack();
              frame.setVisible(true);
    class SortFilterModel extends AbstractTableModel{
        public SortFilterModel(TableModel m){
            model = m;
            rows = new Row[model.getRowCount()];
            for (int i = 0; i < rows.length; i++) {
                rows[i] = new Row();
                rows.index = i;
    public void sort(int c){
    sortColumn = c;
    Arrays.sort(rows);
    fireTableDataChanged();
    public Object getValueAt(int r, int c) {
    return model.getValueAt(rows[r].index, c);
    public boolean isCellEditable(int r, int c){
    return model.isCellEditable(rows[r].index, c);
    public void setValueAt(Object aValue, int r, int c){
    model.setValueAt(aValue, rows[r].index, c);
    public int getRowCount() {
    return model.getRowCount();
    public int getColumnCount(){
    return model.getColumnCount();
    public String getColumnName(int c) {
    return model.getColumnName(c);
    public Class getColumnClass(int c){
    return model.getColumnClass(c);
    private class Row implements Comparable {
    public int index;
    public int compareTo(Object other) {
    Row otherRow = (Row)other;
    Object a = model.getValueAt(index, sortColumn);
    Object b = model.getValueAt(otherRow.index, sortColumn);
    if (a instanceof Comparable) {
    return ((Comparable)a).compareTo(b);
    else{
    return a.toString().compareTo(b.toString());
    public void addRow(Object[] rowData) {
    Row[] oldRows = new Row[rows.length];
    for (int i=0; i<rows.length; i++) {
    oldRows[i] = rows[i];
    rows = new Row[rows.length +1];
    for (int i=0; i < oldRows.length; i++) {
    rows[i] = oldRows[i];
    rows[oldRows.length] = new Row();
    rows[oldRows.length].index = oldRows.length;
    addRow (rowData);
    //model.addRow(rowData);
    fireTableDataChanged();
    private TableModel model;
    private int sortColumn;
    private Row[] rows;

Maybe you are looking for

  • How do I print Mail attachment without saving it first

    I'm new to Mavericks.  With Mail in Lion, I could scroll to the bottom of an email and double click on the icon for the Word doc or pdf attachment to open it, then hit command P to print it. With Mavericks, it appears that I have to first "save" the

  • About Logical Database

    Hi gurus, How to restrict the retrieving of data using logical database? I mean, i have a requirement of retrieving Open transaction data only for my program. i used CHECK keyword as well as IF statement but it doesnt work...can anyone tells me those

  • Multiple status bars in forms 9i

    I have recently upgraded from forms 6i to 9i. I have removed some stuff (like the default menu). I am close to being done with this upgrade. I have one issue that I am having difficultly with. When I load my form, that form gets a status bar. I have

  • HT1414 I'm trying to reset my iphone by using itunes and I'm having the hardest time can anyone help me?

    Hi, I'm trying to reset my iphone 3 but, I'm having the hardest time. Can anyone please help me?

  • Driver for Canon MF3200 Series?

    I have a PC, a newly-bought Mac and a Canon MF3240 printer. My PC prints well with Bonjour through AirPort Extreme. But there is no available driver of this printer for Mac... I would appreciate if Apple team can notice my message, and I am also wait