关于无法解析javax.swing.JTable的问题
/** Datail.java
*
* Created on __DATE__, __TIME__
*/
package readerMange;
import java.util.Iterator;
import java.util.List;
import javax.swing.table.DefaultTableModel;
import com.sun.awt.AWTUtilities;
import dbConntect.Datause;
/**
*
* @author __USER__
*/
@SuppressWarnings("serial")
public class Datail extends javax.swing.JFrame {
/** Creates new form Datail */
public Datail() {
dao =new Datause();
initComponents();
AWTUtilities.setWindowOpacity(this, 0.7f);
//AWTUtilities.setWindowOpaque(this, false);
}
private void initComponents() {
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager
.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (Exception e) {
e.printStackTrace();
}
jPanel1 = new javax.swing.JPanel();
jScrollPane1 = new javax.swing.JScrollPane();
jTable1 = new javax.swing.JTable();
jButton1 = new javax.swing.JButton();
jButton2 = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setUndecorated(true);
jTable1.setFont(new java.awt.Font("Microsoft YaHei UI", 0, 14));
dftm = (DefaultTableModel) jTable1.getModel();
columnNames = new String[] { "姓名", "书一","详情" ,"书二","详情","书三","详情","书四","详情"};
dftm.setColumnIdentifiers(columnNames);
jScrollPane1.setViewportView(jTable1);
jButton1.setText("\u9000\u51fa");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
jButton2.setText("\u5237\u65b0");
jButton2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton2ActionPerformed(evt);
}
});
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(
jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(jPanel1Layout.createParallelGroup(
javax.swing.GroupLayout.Alignment.LEADING).addComponent(
jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 800,
Short.MAX_VALUE).addGroup(
jPanel1Layout.createSequentialGroup().addGap(202, 202, 202)
.addComponent(jButton2,
javax.swing.GroupLayout.PREFERRED_SIZE, 140,
javax.swing.GroupLayout.PREFERRED_SIZE).addGap(
162, 162, 162).addComponent(jButton1,
javax.swing.GroupLayout.PREFERRED_SIZE, 140,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(156, Short.MAX_VALUE)));
jPanel1Layout
.setVerticalGroup(jPanel1Layout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(
jPanel1Layout
.createSequentialGroup()
.addComponent(
jScrollPane1,
javax.swing.GroupLayout.PREFERRED_SIZE,
385,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(
javax.swing.,
18, Short.MAX_VALUE)
.addGroup(
jPanel1Layout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(
jButton2,
javax.swing.GroupLayout.PREFERRED_SIZE,
44,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(
jButton1,
javax.swing.GroupLayout.PREFERRED_SIZE,
39,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addContainerGap()));
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(
getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(layout.createParallelGroup(
javax.swing.GroupLayout.Alignment.LEADING).addComponent(
jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE));
layout.setVerticalGroup(layout.createParallelGroup(
javax.swing.GroupLayout.Alignment.LEADING).addGroup(
layout.createSequentialGroup().addComponent(jPanel1,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addContainerGap()));
pack();
}// </editor-fold>
//GEN-END:initComponents
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
initTable();
}
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
this.dispose();
}
@SuppressWarnings( { "unchecked" })
private void initTable() {
List ul = dao.getDatails();
Iterator it = ul.iterator();
String[] data = new String[9];
dftm.setDataVector(null, columnNames);
while (it.hasNext()) {
List userlist = (List) it.next();
data[0] = (String) userlist.get(0);
data[1] = (String) userlist.get(1);
if(((String)userlist.get(2)).equals("0")){
data[2]="已还";
}else if(((String)userlist.get(2)).equals("1")){
data[2]="未还";
}else {
data[2]=null;
}
data[3] = (String) userlist.get(3);
if(((String)userlist.get(4)).equals("0")){
data[4]="已还";
}else if(((String)userlist.get(4)).equals("1")){
data[4]="未还";
}else {
data[4]=null;
}
data[5] = (String) userlist.get(5);
if(((String)userlist.get(6)).equals("0")){
data[6]="已还";
}else if(((String)userlist.get(6)).equals("1")){
data[6]="未还";
}else {
data[6]=null;
}
data[7] = (String) userlist.get(7);
if(((String)userlist.get(8)).equals("0")){
data[8]="已还";
}else if(((String)userlist.get(8)).equals("1")){
data[8]="未还";
}else {
data[8]=null;
}
dftm.addRow(data);
}
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new Datail().setVisible(true);
}
});
}
//GEN-BEGIN:variables
// Variables declaration - do not modify
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton2;
private javax.swing.JPanel jPanel1;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JTable jTable1;
private Datause dao;
private String[] columnNames;
private DefaultTableModel dftm;
// End of variables declaration//GEN-END:variables
}