0

In my table model, I give it the data, put it in a 2d array, but it still does not show up. This table model has worked for me in the past, so I have no idea why it is not. Nothing is displayed when using this. I KNOW for a fact that the data 2D array is getting data in it.

public class Returns extends javax.swing.JFrame {
    SearchTableModel stm;
    public Returns() {
        stm = new SearchTableModel();
        initComponents();
    }

    public void search(String query) {
        stm.search(query);
    }
    @SuppressWarnings("unchecked")
    private void initComponents() {
        jScrollPane2 = new javax.swing.JScrollPane();
        jTable2 = new javax.swing.JTable();
        jTable2.setModel(stm);
        jTable2.setMinimumSize(new java.awt.Dimension(200, 200));
        jScrollPane2.setViewportView(jTable2);
        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
        layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 1255, Short.MAX_VALUE));
        layout.setVerticalGroup(
        layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 651, Short.MAX_VALUE));
        pack();
    }

    public static void main(String args[]) {
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | javax.swing.UnsupportedLookAndFeelException ex) {
        java.util.logging.Logger.getLogger(Returns.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        java.awt.EventQueue.invokeLater(() -> {
            new Returns().setVisible(true);
        });
    }
    public void setColumns(String... someColumns) {
        stm.setColumns(someColumns);
    }
    public void setEdits(boolean... someEdits) {
        stm.setEdits(someEdits);
    }
    public void setTypes(Class<?>... someTypes) {
        stm.setTypes(someTypes);
    }
    public int dataSize() {
        return stm.size();
    }    

    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JTable jTable2;
    private class SearchTableModel extends KenTableModel {
        protected com.kenergycorp.databases.DatabaseServer database;
        public SearchTableModel() {
            super();
            try {
                database = new com.kenergycorp.databases.MSSQL.LocalTestEnvironment();
            }
            catch (Exception e) {System.out.println("Failed db connection!");}
        }
        public void search(String query) {
            database.query(query);
            boolean found = false;
            data = new ArrayList<Object[]>();
            while (database.next()) {
                ArrayList<String> returnVal = new ArrayList<>();
                found = true;
                for(String colName : column) returnVal.add(database.getValue(colName));
                Object[] results = returnVal.toArray();
                data.add(results);
            }
            if (!found) JOptionPane.showMessageDialog(null, "Search returned no matches.", "No results", JOptionPane.WARNING_MESSAGE);
            else setVisible(true);
            fireTableDataChanged();
            System.out.println(data.size() + " " + column.length + " " + types.length + " " + editable.length);

        }
        public void setColumns(String[] someColumns) {
            column = someColumns;
        }
        public void setTypes(Class<?>[] someTypes) {
            types = someTypes;
        }
        public void setEdits(boolean[] someEdits) {
            editable = someEdits;
        }
        public int size() {
            return data.size();
        }
    }
}
Rabbit Guy
  • 1,840
  • 3
  • 18
  • 28
  • Did you debug your application? I guess `search()` fills the model but I don't see it being called anywhere. Also, I don't know `KenTableModel` so it's hard to say whether something is wrongly configured etc. – Thomas Mar 18 '16 at 15:39
  • Search gets called in another class. The search method executes. I see the data and it is added to the data 2d array... – Rabbit Guy Mar 18 '16 at 15:40
  • Do you see the table at all, i.e. columns, etc. are set correctly? – Thomas Mar 18 '16 at 15:43
  • Nothing. No columns. Not data. Nothing... – Rabbit Guy Mar 18 '16 at 15:43
  • Try to check whether the table itself is being displayed, whether `getColumnName(int)` etc. is called etc. It can be quite a few things from wrong configuration of the table model, wrong/missing ui configuration (e.g. `jScrollPane2` might not have been added to the frame) etc. – Thomas Mar 18 '16 at 15:49

0 Answers0