表模型不在Java中显示

时间:2016-03-18 15:32:42

标签: java abstracttablemodel

在我的表模型中,我给它数据,把它放在一个二维数组中,但它仍然没有显示出来。这个表模型过去对我有用,所以我不知道它为什么不是。使用此功能时不显示任何内容。我知道数据2D阵列正在获取数据的事实。

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();
        }
    }
}

0 个答案:

没有答案