Results 1 to 4 of 4
  1. #1
    igorland is offline Member
    Join Date
    Jan 2013
    Posts
    89
    Rep Power
    0

    Default AbstractTableModel: getValueAt() not called

    Hello.

    I have a controller that creates a new JTable when a button is pressed to switch on a card.

    Java Code:
    public void displayTabWindsAloft() 
        {
            CardLayout card = (CardLayout)viewMainFrame.panelContext.getLayout();
            card.show(viewMainFrame.panelContext, "cardWindsAloft");
                
            System.out.println("UPDATE WINDS ALOFT");
            
            viewMainFrame.createPanelWindsAloft();
        }
    In my view, I got the following:

    Java Code:
    public void createPanelWindsAloft()
        {
            //... creating other GUI
            
            appSingleton.tblWindsAloft = new javax.swing.JTable(new Model_TableWindsAloft());
            JScrollPane scrollWindsAloft = new JScrollPane(appSingleton.tblWindsAloft,JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
            //tblWindsAloft.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
            appSingleton.tblWindsAloft.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS);
            appSingleton.tblWindsAloft.setFillsViewportHeight(true);
            pnlWindsAloftTable.add(scrollWindsAloft, BorderLayout.CENTER); 
            
            // ... Creating other GUI
            
        }
    And my table model is as follows:

    Java Code:
    import java.util.ArrayList;
    import java.util.Arrays;
    import java.util.List;
    import javax.swing.table.AbstractTableModel;
    
    
    public class Model_TableWindsAloft extends AbstractTableModel
    {
        AppSingleton appSingleton = AppSingleton.getInstance( );
        
        String[] columnNames = {"ICAO","Name","Type"};
            
        private List<List<String>> tableData = new ArrayList<>();
        
    
        public Model_TableWindsAloft()
        {
            tableData=createData();
            
            System.out.println("CONSTRUCTOR? "+tableData);
        }
        
    
        @Override
        public int getRowCount() 
        {
            System.out.println("DATA COUNT? "+tableData.size());
    
            return(tableData.size());
        }
        
        @Override
        public int getColumnCount() {
            return(columnNames.length);
        }
        
        @Override
        public String getColumnName(int column) 
        {
            return columnNames[column] ;
        }
    
        @Override
        public Object getValueAt(int rowIndex, int columnIndex) 
        {
            System.out.println("WHAT IS DATA 1? "+tableData);
            
            List<String> data = tableData.get(rowIndex);
            
            System.out.println("WHAT IS DATA 2? "+data);
            
                switch(columnIndex) 
                {
                    case 0: 
                        return data.get(0);
                    case 1:
                        return data.get(1);
                    case 2:
                        return data.get(2);
                    default: 
                        return null;
                }
        }
    
    
        private List<List<String>> createData()
        {
            List<List<String>> finalResult = new ArrayList<>();
            
            for (int i=0; i<appSingleton.flightPlanShared.size(); i++)
            {       
                if(appSingleton.flightPlanShared.get(i).size()>2)
                {
                    List<String> components = new ArrayList<>();
                    
                    components.add(appSingleton.flightPlanShared.get(i).get(2));
                    components.add(appSingleton.flightPlanShared.get(i).get(1));
                    components.add(appSingleton.flightPlanShared.get(i).get(0));
    
                    finalResult.add(components);
                }
            }
    
            System.out.println("DATA CREATED: "+finalResult);
            
            return finalResult;
        }
    }

    No data is shown on the table. My print-out is as follows:

    UPDATE WINDS ALOFT
    DATA CREATED: [[XXX , XXX, XXX], [XXX, XXX, XXX], [XXX, XXX, XXX]]
    CONSTRUCTOR? [[YYY, YYY, YYY], [YYY, YYY, YYY], [YYY, YYY, YYY]]
    DATA COUNT? 0
    DATA COUNT? 0

    Obviously, the data has been created but the method getValueAt(int rowIndex, int columnIndex) is not called.

    Thank you!

  2. #2
    igorland is offline Member
    Join Date
    Jan 2013
    Posts
    89
    Rep Power
    0

    Default Re: AbstractTableModel: getValueAt() not called

    This is getting really weird. I have the same issue even if I pass the prepared dataset to the Constructor.

    I have four Card panels. On one card, I get data for the first point; on the second and third cards, for the second and third points; on the fourth, the data should be presented in the JTable.

    This is how I changed it now.

    Java Code:
    String[] columnNames = {"ICAO","Name","Type"};
        
        private List<List<String>> tableData = new ArrayList<>();
    
        public Model_TableWindsAloft(List<List<String>> tableData)
        {
            this.tableData = tableData;
            
            System.out.println("CONSTRUCTOR? "+tableData);
        }
    
    @Override
        public Object getValueAt(int rowIndex, int columnIndex) 
        {
            System.out.println("WHAT IS DATA 1? "+tableData);
            
            List<String> data = tableData.get(rowIndex);
            
            System.out.println("WHAT IS DATA 2? "+data);
            
                switch(columnIndex) 
                {
                    case 0: 
                        return data.get(0);
                    case 1:
                        return data.get(1);
                    case 2:
                        return data.get(2);
                    default: 
                        return null;
                }
        }

    On controller:

    Java Code:
    public void displayTabWindsAloft() 
        {
            CardLayout card = (CardLayout)viewMainFrame.panelContext.getLayout();
            card.show(viewMainFrame.panelContext, "cardWindsAloft");
                
            System.out.println("UPDATE WINDS ALOFT");
    
            viewMainFrame.createPanelWindsAloft();
        }
    ON VIEW:

    Java Code:
    public void createPanelWindsAloft()
        {
            javax.swing.JTable tblWindsAloft = new javax.swing.JTable(new Model_TableWindsAloft(createDataForWindsTable()));
            JScrollPane scrollWindsAloft = new JScrollPane(tblWindsAloft,JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
            tblWindsAloft.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS);
            tblWindsAloft.setFillsViewportHeight(true);
            pnlWindsAloftTable.add(scrollWindsAloft, BorderLayout.CENTER); 
        }
    
    public List<List<String>> createDataForWindsTable()
        {
            List<List<String>> finalResult = new ArrayList<>();
            
            System.out.println("SIZE: "+finalResult.size());
            
            for (int i=0; i<appSingleton.flightPlanShared.size(); i++)
            {    
                String icao;
                String name;
                String type;
                
                if(appSingleton.flightPlanShared.get(i).size()>2)
                {
                    icao = appSingleton.flightPlanShared.get(i).get(2);
                    name = appSingleton.flightPlanShared.get(i).get(1);
                    type = appSingleton.flightPlanShared.get(i).get(0);
                }
                else
                {
                    icao = "";
                    name = "";
                    type = "";
                }
                    
                List<String> components = new ArrayList<>();
                    
                components.add(icao);
                components.add(name);
                components.add(type);
                    
                System.out.println("COMPONENTS: "+components);
    
                finalResult.add(components);
                
            }
            
            System.out.println("DATA CREATED: "+finalResult);
            
            return finalResult;
        }
    My table remains blank and this is the print-out:

    When the application is created:

    SIZE: 0
    COMPONENTS: [, , ]
    COMPONENTS: [, , ]
    COMPONENTS: [, , ]
    DATA CREATED: [[, , ], [, , ], [, , ]]
    CONSTRUCTOR? [[, , ], [, , ], [, , ]]
    DATA COUNT? 3


    When I finished entering input on the first three Card panels and switching to the 4th panel:

    UPDATE WINDS ALOFT
    SIZE: 0
    COMPONENTS: [LAS VEGAS/MC CARRAN , KLAS, PORTDEP]
    COMPONENTS: [LOS ANGELES INTL, KLAX, PORTDEST]
    COMPONENTS: [SEATTLE-TACOMA INTL, KSEA, PORTALT]
    DATA CREATED: [[LAS VEGAS/MC CARRAN , KLAS, PORTDEP], [LOS ANGELES INTL, KLAX, PORTDEST], [SEATTLE-TACOMA INTL, KSEA, PORTALT]]
    CONSTRUCTOR? [[LAS VEGAS/MC CARRAN , KLAS, PORTDEP], [LOS ANGELES INTL, KLAX, PORTDEST], [SEATTLE-TACOMA INTL, KSEA, PORTALT]]
    DATA COUNT? 3
    DATA COUNT? 3
    DATA COUNT? 3
    DATA COUNT? 3
    DATA COUNT? 3
    DATA COUNT? 3
    DATA COUNT? 3
    WHAT IS DATA 1? [[, , ], [, , ], [, , ]]
    WHAT IS DATA 2? [, , ]
    WHAT IS DATA 1? [[, , ], [, , ], [, , ]]
    WHAT IS DATA 2? [, , ]
    WHAT IS DATA 1? [[, , ], [, , ], [, , ]]
    WHAT IS DATA 2? [, , ]


    Also, if I create my data at the compilation stage:

    Java Code:
    public List<List<String>> createDataForWindsTable()
        {
            List<List<String>> finalResult = new ArrayList<>();
            
            System.out.println("SIZE: "+finalResult.size());
            
            String a1 = "LAS VEGAS/MC CARRAN ";
            String a2 = "KLAS";
            String a3 = "PORTDEP";
            
            List<String> a = new ArrayList<>();
            a.add(a1);
            a.add(a2);
            a.add(a3);
            
            String b1 = "LOS ANGELES INTL";
            String b2 = "KLAX";
            String b3 = "PORTDEST";
            List<String> b = new ArrayList<>();
            b.add(b1);
            b.add(b2);
            b.add(b3);
            
            String c1 = "SEATTLE-TACOMA INTL";
            String c2 = "KSEA";
            String c3 = "PORTALT";
            List<String> c = new ArrayList<>();
            c.add(c1);
            c.add(c2);
            c.add(c3);
            
            finalResult.add(a);
            finalResult.add(b);
            finalResult.add(c);
            
            System.out.println("DATA CREATED: "+finalResult);
            
            return finalResult;
        }
    ... everything works fine! I am really puzzled here!

  3. #3
    SurfMan's Avatar
    SurfMan is offline Godlike
    Join Date
    Nov 2012
    Location
    The Netherlands
    Posts
    1,964
    Rep Power
    7

    Default Re: AbstractTableModel: getValueAt() not called

    Does your application swallow its Exceptions, i.e. do you have an empty catch block somewhere?
    "It's not fixed until you stop calling the problem weird and you understand what was wrong." - gimbal2 2013

  4. #4
    igorland is offline Member
    Join Date
    Jan 2013
    Posts
    89
    Rep Power
    0

    Default Re: AbstractTableModel: getValueAt() not called

    Quote Originally Posted by SurfMan View Post
    Does your application swallow its Exceptions, i.e. do you have an empty catch block somewhere?
    I do but they are not related to this JTable code. Besides, in the contractor all data is passed as needed. I do not understand, why it is not used by getValueAt()...

    Thanks.

Similar Threads

  1. trying to use AbstractTableModel
    By stefan_banu in forum Advanced Java
    Replies: 1
    Last Post: 05-21-2013, 02:35 PM
  2. creating a AbstractTableModel
    By darrenw in forum AWT / Swing
    Replies: 0
    Last Post: 10-31-2010, 12:04 PM
  3. The right way to inherit AbstractTableModel
    By skywriter in forum New To Java
    Replies: 3
    Last Post: 10-19-2010, 11:28 AM
  4. ArrayIndexOutOfBounds, JTable.getValueAt
    By ZackO in forum AWT / Swing
    Replies: 10
    Last Post: 10-17-2010, 07:29 PM
  5. DefaultTableModel vs AbstractTableModel
    By chyrl in forum AWT / Swing
    Replies: 4
    Last Post: 05-02-2010, 12:10 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •