JTable add row as the first row problem?

table.addRow();
i want it show on the first row
how to do?

JTable doesn't have an addRow() method. Add add data to the TableModel not the table.
The DefaultTableModel has addRow() and insertRow() methods.

Similar Messages

  • I am unable to add contacts with their phone numbers. I add one press done and then it shows up but when I add another one the first one is deleted. How can I add them and make sure they stay.  Upper left hand corner there is partial circle w/ arrow

    I Unable to add contacts. I add one and then press done.  It shows up but after I add another one the first one is gone.  How do I save them?

    Hi,
    Troubleshooting a start up script can be difficult. There are some third party programs that also keep logs of start up programs, however for Firefox this may be different.
    Is Firefox a startup program? [http://www.winxptutor.com/msinfo32.htm]
    Its also possible to check the Web developer tools for any scripts in a page: [https://developer.mozilla.org/en-US/docs/Tools/Debugger]
    In the control panel there is also Administrative tools to view event logs, but this may be something a local technician can walk you through.

  • How to add -Select- as the first value in dropdownbox?

    Hi All,
    I am having a dropdownbox with the set of values. I need to add -SELECT- as the first and default value. Please do advise how to achieve this.
    Code and screenshot below.
    var oModel = new sap.ui.model.odata.ODataModel("../../services/admin/typesTable.xsodata/", false);
    var oSort = new sap.ui.model.Sorter("ID", false);
    var lblType = new sap.ui.commons.Label();
    lblType.setText("Type");
    var ddbType = new sap.ui.commons.DropdownBox();
    ddbType.setRequired(true);
    var oItemTemplate = new sap.ui.core.ListItem();
    oItemTemplate.bindProperty("text", "NAME");
    oItemTemplate.bindProperty("key", "ID");
    ddbType.setModel(oModel);
    ddbType.bindItems("/TYPES", oItemTemplate, oSort);
    lblType.setLabelFor(ddbType);
    oChildLayout.createRow(lblType, ddbType);
    Thanks in advance
    Aravindh

    Hi,
    Refer this discussion on exact requirement empty/"all" entry in DropdownBox with OData model - cleanest solution
    Regards,
    Chandra

  • Single Master, multiple details add-rows problem

    Hi, hope to get a replay at least this time (last threads have gone unreplied :-( )
    We've built a master-multiple details table. Everything in visualization has worked OK until we've got the need to add rows to each
    detail table separately (i.e. for same master row, one could add N rows to one detail and M rows to the other).
    Keeping the standard "addRows" table buttons doesn't work because the same addRows event is fired for both the subtables, so
    adding a row in one just adds a row also to the other, until a dedlock situation is reached.
    So we tried to set a different button so we could intercept the originator table (SOURCE_PARAM) in the processForm but here we're facing
    some big problems.
    First at all, the methods and names are correct: we've tried to use the same code (cut and paste) for the table putting the inner table "outside"
    and buttons are working as expected.
    But when the detail table is put back "within" the master, what happens is that the AM method called by pFR in the Controller is executed, so
    we reach the end of the processFormRequest, but at this time something happens and we get the exception error message reported more below.
    I've read that via the VL it is not the original detail VO instance which is showed, so wonder if the error has something to do with that...
    So to summarize:
    1) all the objects exist and are ok, and the VL is defined OK; and indeed the standard AddRows management works (as said, the problem
    is that we need to differentiate two different details...)
    2) the methods are OK as they work as soon as the details are put outside the master table.
    Any suggestion ? Do we need to refer to a specific details VO instance ???
    Thanks in advance. Rgds.
    GN
    ## Detail 0 ##
    oracle.apps.fnd.framework.OAException: oracle.jbo.InvalidObjNameException: JBO-25005: Nome oggetto per il tipo Oggetto vista non valido
         at oracle.apps.fnd.framework.OAException.wrapperException(OAException.java:891)
         at oracle.apps.fnd.framework.webui.OAPageErrorHandler.prepareException(OAPageErrorHandler.java:1145)
         at oracle.apps.fnd.framework.webui.OAPageErrorHandler.processErrors(OAPageErrorHandler.java:1408)
         at oracle.apps.fnd.framework.webui.OAPageBean.processFormRequest(OAPageBean.java:2704)
         at oracle.apps.fnd.framework.webui.OAPageBean.preparePage(OAPageBean.java:1707)
         at oracle.apps.fnd.framework.webui.OAPageBean.preparePage(OAPageBean.java:511)
         at oracle.apps.fnd.framework.webui.OAPageBean.preparePage(OAPageBean.java:432)
         at OA.jspService(OA.jsp:33)
         at com.orionserver.http.OrionHttpJspPage.service(OrionHttpJspPage.java:56)
         at oracle.jsp.runtimev2.JspPageTable.service(JspPageTable.java:317)
         at oracle.jsp.runtimev2.JspServlet.internalService(JspServlet.java:465)
         at oracle.jsp.runtimev2.JspServlet.service(JspServlet.java:379)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
         at com.evermind.server.http.ServletRequestDispatcher.invoke(ServletRequestDispatcher.java:727)
         at com.evermind.server.http.ServletRequestDispatcher.forwardInternal(ServletRequestDispatcher.java:306)
         at com.evermind.server.http.HttpRequestHandler.processRequest(HttpRequestHandler.java:767)
         at com.evermind.server.http.HttpRequestHandler.run(HttpRequestHandler.java:259)
         at com.evermind.server.http.HttpRequestHandler.run(HttpRequestHandler.java:106)
         at EDU.oswego.cs.dl.util.concurrent.PooledExecutor$Worker.run(PooledExecutor.java:803)
         at java.lang.Thread.run(Thread.java:534)
    oracle.apps.fnd.framework.OAException: oracle.jbo.InvalidObjNameException: JBO-25005: Nome oggetto per il tipo Oggetto vista non valido
         at oracle.apps.fnd.framework.OAException.wrapperException(OAException.java:891)
         at oracle.apps.fnd.framework.webui.OAPageErrorHandler.prepareException(OAPageErrorHandler.java:1145)
         at oracle.apps.fnd.framework.webui.OAPageErrorHandler.processErrors(OAPageErrorHandler.java:1408)
         at oracle.apps.fnd.framework.webui.OAPageBean.processFormRequest(OAPageBean.java:2704)
         at oracle.apps.fnd.framework.webui.OAPageBean.preparePage(OAPageBean.java:1707)
         at oracle.apps.fnd.framework.webui.OAPageBean.preparePage(OAPageBean.java:511)
         at oracle.apps.fnd.framework.webui.OAPageBean.preparePage(OAPageBean.java:432)
         at OA.jspService(OA.jsp:33)
         at com.orionserver.http.OrionHttpJspPage.service(OrionHttpJspPage.java:56)
         at oracle.jsp.runtimev2.JspPageTable.service(JspPageTable.java:317)
         at oracle.jsp.runtimev2.JspServlet.internalService(JspServlet.java:465)
         at oracle.jsp.runtimev2.JspServlet.service(JspServlet.java:379)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
         at com.evermind.server.http.ServletRequestDispatcher.invoke(ServletRequestDispatcher.java:727)
         at com.evermind.server.http.ServletRequestDispatcher.forwardInternal(ServletRequestDispatcher.java:306)
         at com.evermind.server.http.HttpRequestHandler.processRequest(HttpRequestHandler.java:767)
         at com.evermind.server.http.HttpRequestHandler.run(HttpRequestHandler.java:259)
         at com.evermind.server.http.HttpRequestHandler.run(HttpRequestHandler.java:106)
         at EDU.oswego.cs.dl.util.concurrent.PooledExecutor$Worker.run(PooledExecutor.java:803)
         at java.lang.Thread.run(Thread.java:534)

    Any suggestion on this ? What I need, in other words, is to put two details table under the same master table...

  • The first REAL problem with an all touch screen...

    today at work my screen would not work for any of the phone related "touches"...the contact list would come up, but you couldnt select any contact to make a call, the keyboard button would not respond to touch, so no call there, no recents, no favorites...so basicly i couldnt make a call at all on my phone, and because i was not home i could not Restore my phone till i was in front of my computer...BIG PROBLEM

    Did you perform either a soft-reboot by pressing & holding the 'home' button for several seconds?
    OR
    a hard-reboot by pressing & holding both the 'home' button and the 'keyguard' button for several seconds?
    You didn't did you? No worries, many of us are new to this thing = }
    Try it out, and good luck! It worked for me. But yeah, it would be nice if the iPhone didn't freeze within the first month of purchase, right? It's also a bit odd, when most people are used to the blue-screen of death from Windows, or the kernal-panic of OSX. Maybe the iPhone deserves it's own 'HELP I'm frozen and need a reboot' screen of death....

  • In iMovie 11 I can not add photos after the first video.

    I keep trying to add a photo taken with my iPhone to a project, but it never shows up.  Instead of showing up the video immediately previous to the photo displays a still shot with Ken Burns. 
    Any thoughts?

    Greetings MadisonP,
    Thanks for your response, but none off your points did helped me.
    I have tried every point but the problem stays.
    There are similar problems in this community and most off those points i have tried also.
    https://discussions.apple.com/message/13179627#13179627
    https://discussions.apple.com/message/12584273#12584273
    https://discussions.apple.com/message/13176853#13176853
    https://discussions.apple.com/message/12527975#12527975
    https://discussions.apple.com/message/12776786#1277
    These are the discussions i have found and al of those solutions didn't work with me.
    I hope there will be someone with a solution.
    Thanks Mike

  • The First iTunes Problem I Ever Had...

    I love iTunes and iTunes 7 is the best media player in the history of any media players. I recently had problems where something must've iterphered with it and mixed the settings all up so now even after 2 system restores and uninsalling and reinstalling it about 100 billion times I still don't know how to fix it so if theres anyone out there who can help me please do this is the message box that comes up:
    I thank whoever can help me sincerely...

    Error -200 is basicly caused by old and/or incorrectly installed quicktime files.
    Since you did a restore tho you need to do the extra step of going to "Windows update" site and updating windows....then goto the PC makers site and install ALL updates for your PC model.
    After that goto (In windows) control panel>add and remove and uninstall itunes AND quicktime.
    Go here and roll down to "Clean up iTunes installer files on the computer" (Don't download or install yet itunes) http://docs.info.apple.com/article.html?artnum=93976
    Extra Measure Scan the system for malware with your adware/spyware program or ewido http://www.ewido.com Sometimes malware "Fudges" with installs of itunes.
    Now disable antivirus and security programs then goto apple.com and download/install itunes again

  • When I'm on microsoft word and typing and get to the  bottom of the page a new page doesn't just come up, i have to manually put it there so then when i go back and add stuff to the first page i loose whatever was at the bottom. how do i stop this?

    When I'm on microsoft word on my macbook air and get to the bottom a the page, a new page does not come up. i have to manually insert one. so then when i go back to edit my work and add something in what ever was at the bottom of the page disappears. how can i stop this from happening or change it so a new page opens by itself?

    It sounds like you have chosen a publishing template rather than a word processing template. There are two basic modes in MS Word: word processing and publishing layout. Word processing mode (and all word processing templates) have a continuous text box in the page for writing text. The publishing layout mode (and publishing templates) are documents that have text boxes placed for articles, titles, pictures, etc. Be sure to choose the word document template and you’ll get what you expect. Do not choose the word publishing document.

  • "You are opening the application"..."for the first time" problem

    Hi -
    We recently upgraded to Mounatin Lion and when opening a couple of different applications (Quickbooks and Vectorworks) we often, but not always, get a warning message saying something like "You are opening the application ____ for the furst time" even though the application has been opened many times before.
    I've seen a few older suggestions in the archives (pre Mountain Lion) that involve opening a Terminal window and entering some lines of code.  Is that my only solution, or is there a file that I can trash or something else?
    Thanks -

    Having this exact same problem - Not just after the upgrade, but began a few months in.
    Hope a solution comes up. Most tips online are from 2006 or 2009.

  • Add rows to datagridview

    Hi All,
    I am having problems adding a new row to a datagridview control in my form. I have a simple form with a textbox, a button and a datagridview. When the user types in an item number and clicks on the button, the system will populate the datagridview with the relevant data from the database. All these works fine but, when the user tries to add another record, the first record added to the datagridview is cleared off the datagridview before the next record is displayed. I would like the datagridview to add all the records without clearing the screen. The datagridview is not bounded to the database
    Can someone please help.
    Regards

    This is not an oracle problem. It's more based on handling datagrid in right way.
    How often do you call datagrid.databind()? Calling this loads all records again from database and clears all your newly added rows.
    Christian

  • Unable to hide the first page in the form

    Hi ,
    I am trying to design a dynamic form that has three pages. The form is being used in a LiveCycle process and during the process initiation, only the second page should be visible and the first and third pages should be hidden. I am trying to hide the first and the third pages using JavaScript. I noticed that the third page is being hidden but the first page gets displayed as an empty page. Based on this behavior here are couple of questions I need guidance with
    Can we hide the first page within a form? If so why am I seeing this inconsistent behavior when hiding the first and third pages?
    If the first page can not be hidden then is there a workaround to achieve my goal of re-arranging the pages so that I can add content to the first page dynamically and shift the previous content on the first page to the second page?
    Any suggestions will be appreciated.
    Thanks,
    Samanthapudi

    Hi,
    You've originally said.
    in the first page i don't want data in main window...
    yet using a command node to trigger the next page means you have to include a (presumably) empty main window in the first page.
    Your main window has to contain some output (a table usually) and it's contents are the same on every page (only it's height can change).  So, you can't have a blank main window on page 1 and a main window with data on pages 2 and 3.
    Remove the main window from page 1, set page2 as the next page for page 1.
    As for how to trigger page 3 you'll need to provide more detail on what the condition is.  Do you want multiple copies of page 2 to hold all of the main window data, or just one?  Do you want one copy of page 2 then the rest of the data on multiple copies of page 3.  Be specific.
    Regards,
    Nick

  • Playing a second swf when the first one's finished

    I have 2 swf files (the FLA's too) and want one to play then
    the second. - I'd add the second to the timeline of the first, but
    the second is a complete site and contains many referenced
    "gotoandplay" links which would all need changing. So....I really
    just need a way for the second swf to play after the first one's
    finished. I tried using the load external movie clip behaviour, but
    couldn't make it work. Can I use the first swf as a preloader
    without affecting the timeline on the main swf? I canspare a couple
    of frames at the start of the second movie for that, but don't know
    how to set it up - can anyone help?
    I also want the custom cursor to remain only in the first
    swf, and go back to default on the second.
    main (second) movie:
    http://mysticalbillyo.com
    first movie:
    http://mysticalbillyo.com/intro.swf

    I think you may want to create a 'master' loading swf, rather
    than loading the second movie into the first, and use the
    MovieClipLoader class to call and load new movies into the master
    container.
    Set up a new swf, that is the same size as the others. you'll
    set up a function on the first frame and then use that function to
    load all subsequent content into the master document. You can also
    use methods of the class to add things like preloaders and other
    event handlers. so for instance, at the last frame of the intro
    swf, you'd add a 'call' to the function in the master telling it to
    load the next movie in the sequence. I'll add the call you will
    need on the bottom of the code example below.
    PS. ------------------------------------
    I'm not one to solicit, however I have (awhile ago) developed
    a Component that you may be interested in for your site, although
    it has not been package and ready for distribution, it does
    function - called 'glitterMouse', and produces a twinkling mouse
    trail effect when you move the cursor, mush like the onRollOver
    animation that you'd painstakingly made (ouch) except that it use
    random twinkle generation at run-time, and has many property
    settings, like color, quantity, gravity, and so on. It might be a
    nice addition to your 'wand' cursor, and would not 'replace it' as
    it's not a 'cursor' but an effect generator.
    If you are interested, an example of it in action (although
    you can't purcahse it from there ... yet) can be seen on my site
    at: www.beechstudios.com goto the 'Flash' section, it's the first
    one listed.
    Just thought I'd throw that out there, sorry all, it just
    fits :]
    OK the code for you, add this to the first frame of the
    'master' swf, then add the code at the bottom to the end of the
    intro swf in the last frame.
    EDIT: this is AS2 code, to use AS3 code do something more
    like the methods as described above, yet I would still consider
    placing all content within a 'master' loading doc, and replaceing
    or removeing previously loaded children.

  • How to keep the first row fixed in a JTable, with sorting, and bellow the headers ?

    I am trying to change the following code so then the fixed rows will stay on top(but below the headers!), but when I change getContentPane().add(fixedScroll, BorderLayout.SOUTH); to getContentPane().add(fixedScroll, BorderLayout.NORTH); it stays above the headers. How can I put the first rows on top, but below the headers ? Thanks.
    import java.awt.*; 
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.table.*;
    import javax.swing.event.*;
    * @version 1.0 03/05/99
    public class FixedRowExample extends JFrame {
      Object[][] data;
      Object[] column;
      JTable fixedTable,table;
      private int FIXED_NUM = 2;
      public FixedRowExample() {
        super( "Fixed Row Example" );
        data =  new Object[][]{
            {      "a","","","","",""},
            {      "","b","","","",""},
            {      "","","c","","",""},
            {      "","","","d","",""},
            {      "","","","","e",""},
            {      "","","","","","f"},
            {"fixed1","","","","","","",""},
            {"fixed2","","","","","","",""}};
        column = new Object[]{"A","B","C","D","E","F"};
        AbstractTableModel    model = new AbstractTableModel() {
          public int getColumnCount() { return column.length; }
          public int getRowCount() { return data.length - FIXED_NUM; }
          public String getColumnName(int col) {
           return (String)column[col];
          public Object getValueAt(int row, int col) {
            return data[row][col];
          public void setValueAt(Object obj, int row, int col) {
            data[row][col] = obj;
          public boolean CellEditable(int row, int col) {
            return true;
        AbstractTableModel fixedModel = new AbstractTableModel() {     
          public int getColumnCount() { return column.length; }
          public int getRowCount() { return FIXED_NUM; }
          public Object getValueAt(int row, int col) {
            return data[row + (data.length - FIXED_NUM)][col];
        table = new JTable( model );
        table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
        table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
        table.setAutoCreateRowSorter(true);
        fixedTable = new JTable( fixedModel );
        fixedTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
        fixedTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
        JScrollPane scroll      = new JScrollPane( table );
        scroll.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
        JScrollPane fixedScroll = new JScrollPane( fixedTable ) {
          public void setColumnHeaderView(Component view) {} // work around
                                                 // fixedScroll.setColumnHeader(null);
        fixedScroll.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
        JScrollBar bar = fixedScroll.getVerticalScrollBar();
        JScrollBar dummyBar = new JScrollBar() {
          public void paint(Graphics g) {}
        dummyBar.setPreferredSize(bar.getPreferredSize());
        fixedScroll.setVerticalScrollBar(dummyBar);
        final JScrollBar bar1 = scroll.getHorizontalScrollBar();
        JScrollBar bar2 = fixedScroll.getHorizontalScrollBar();
        bar2.addAdjustmentListener(new AdjustmentListener() {
          public void adjustmentValueChanged(AdjustmentEvent e) {
            bar1.setValue(e.getValue());
        scroll.setPreferredSize(new Dimension(400, 100));
        fixedScroll.setPreferredSize(new Dimension(400, 52));  // Hmm...
        getContentPane().add(     scroll, BorderLayout.CENTER);
        getContentPane().add(fixedScroll, BorderLayout.SOUTH);   
      public static void main(String[] args) {
        FixedRowExample frame = new FixedRowExample();
        frame.addWindowListener( new WindowAdapter() {
          public void windowClosing( WindowEvent e ) {
            System.exit(0);
        frame.pack();
        frame.setVisible(true);

    Sorry, this code missed a very important line:
    table.setAutoCreateRowSorter(true);
    So you meant:
    Object[][] header;//class atribute
    header=new Object[][]{//in the constructor
                { "h","i","j","k","l","m"},
                { "h","i","j","k","l","m"}
    public Object getValueAt(int row, int col) {//in the TableModel
            if (row==0){
                return header[row][col];
            else {
                return data[row][col];
    I tried, but when I sort, the first row get sorted with the rest.

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

  • To put a row selected by a number as the first in a JTable

    Hello,
    I have a JTable that is in a scroll pane and I try to get a row that is identifyed by a number how the first in the JTable.
    I use this function to have the required behavior:
    public void scrollToSelectedRow(int rowNmbr){
            int rowHeigth = agendaTab.getRowHeight();
            JScrollBar sb = jScrollPanCalendSupporter.getVerticalScrollBar();
            sb.setValue(rowHeigth * rowNmbr); // rowNmbr
        } // scrollToSelectedRow()The application where I will use the function concern with an scheduled time that can vary ewery
    day in the week (and the times are put in the Jtable).
    So, some time the JTable can have 3 rows, other time it can have 10 or 40 or 0 too...
    In a simple test, the function that I use works fine, but when I use the function in the application
    I have problems: not every time the indicated row become the first in the JTable ..
    Debugging the code I saw that the the value that I get by this statement:
    int max = jScrollPanCalendSupporter.getVerticalScrollBar().getMaximum();is different in the thest program from appliacation program, so I have a clue about what the
    mistake could be...
    I have tried to regulate the behavior of the scoll pane before to call the function,
    trying to have the right value for the "max" variable, by calling repaint() but I didn't get any good
    result with this solution...
    I should like to have some suggestion about how I could have a right value for the variable max
    .....hoping this could be the cause of the mistake...
    Otherwise ever other suggestion is welcome to fix the problem...
    thank you
    regards
    tonyMrsangelo

    Use the following method instead:
    table.getCellRect(...)
    table.scrollRectToVisible(...);

Maybe you are looking for