I can't imagine what you were thinking!
Here is my code. Actually I tried to collect data from a text file and
put them into JTable. But NetBeans shows warning at
tableDCM.setModel() command.
/*
* DCMUpload.java
*
* Created on November 4, 2008, 11:09 PM
*/
package ecgterminal3;
;
import java.io.*;
/**
*
* @author freebird
*/
public class DCMUpload extends javax.swing.JDialog {
public DCMUpload(javax.swing.JFrame app) {
//super(parent);
initComponents();
}
/** Creates new form DCMUpload */
public DCMUpload(java.awt.Frame parent, boolean modal) {
super(parent, modal);
initComponents();
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
File file2 = new File("D:\\NetBeanProject\\ECGTerminal3\\src\
\ecgterminal3\\ToBeUploaded.txt");
BufferedReader reader2 = null;
try{
reader2 = new BufferedReader(new FileReader(file2));
}catch (FileNotFoundException e) {
}
String text2 = null;
String[] words = null;
jPanel1 = new javax.swing.JPanel();
jScrollPane1 = new javax.swing.JScrollPane();
tableDCM = new javax.swing.JTable();
jLabel1 = new javax.swing.JLabel();
uploadButton = new javax.swing.JButton();
cancelButton = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
setName("Form"); // NOI18N
jPanel1.setName("jPanel1"); // NOI18N
jScrollPane1.setName("jScrollPane1"); // NOI18N
String data = null;
try {
data = "";
while ((text2 = reader2.readLine()) != null)
{
words = text2.split(";");
data = data + "{" + words[0] + "," + words[1] + "," +
words[2] + "," + new Boolean(false) + "},";
}
data = data.substring(0, data.length()-1);
}catch (IOException e) {
}
//String field = "DICOM File", "Patient's ID", "Patient's
Name", "Upload";
Object dataobject = "new Object [][] {" + data + "}, new
String [] {'DICOM File', 'Patient ID', 'Patient Name', 'Upload'}";
tableDCM.setModel(new javax.swing.table.DefaultTableModel(
dataobject
/*new Object [][] {
{words[0], words[1], words[2], new Boolean(false)},
{"bbb1", "bbb2", "bbb3", new Boolean(false)},
{"ccc1", "ccc2", "ccc3", new Boolean(false)},
{"ddd1", "ddd2", "ddd3", new Boolean(false)},
{"eee1", "eee2", "eee3", new Boolean(false)}
},
new String [] {
"DICOM File", "Patient's ID", "Patient's Name",
"Upload"
}*/
) {
boolean[] canEdit = new boolean [] {
false, false, false, false
};
public boolean isCellEditable(int rowIndex, int
columnIndex) {
return canEdit [columnIndex];
}
});
tableDCM.setName("tableDCM"); // NOI18N
tableDCM.setSelectionMode(javax.swing.ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
jScrollPane1.setViewportView(tableDCM);
org.jdesktop.application.ResourceMap resourceMap =
org.jdesktop.application.Application.getInstance(ecgterminal3.Main.class).getContext().getResourceMap(DCMUpload.class);
tableDCM.getColumnModel().getColumn(0).setHeaderValue(resourceMap.getString("tableDCM.columnModel.title0")); //
NOI18N
tableDCM.getColumnModel().getColumn(1).setHeaderValue(resourceMap.getString("tableDCM.columnModel.title1")); //
NOI18N
tableDCM.getColumnModel().getColumn(2).setHeaderValue(resourceMap.getString("tableDCM.columnModel.title2")); //
NOI18N
tableDCM.getColumnModel().getColumn(3).setHeaderValue(resourceMap.getString("tableDCM.columnModel.title3")); //
NOI18N
jLabel1.setFont(resourceMap.getFont("jLabel1.font")); //
NOI18N
jLabel1.setText(resourceMap.getString("jLabel1.text")); //
NOI18N
jLabel1.setName("jLabel1"); // NOI18N
uploadButton.setText(resourceMap.getString("uploadButton.text")); //
NOI18N
uploadButton.setName("uploadButton"); // NOI18N
cancelButton.setText(resourceMap.getString("cancelButton.text")); //
NOI18N
cancelButton.setName("cancelButton"); // NOI18N
javax.swing.GroupLayout jPanel1Layout = new
javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addContainerGap()
.addComponent(jLabel1))
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(127, 127, 127)
.addComponent(uploadButton)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(cancelButton)))
.addContainerGap(133, Short.MAX_VALUE))
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(12, 12, 12)
.addComponent(jScrollPane1,
javax.swing.GroupLayout.PREFERRED_SIZE, 375,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(13, Short.MAX_VALUE)))
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addContainerGap()
.addComponent(jLabel1)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED,
230, Short.MAX_VALUE)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(cancelButton)
.addComponent(uploadButton))
.addGap(21, 21, 21))
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING,
jPanel1Layout.createSequentialGroup()
.addContainerGap(39, Short.MAX_VALUE)
.addComponent(jScrollPane1,
javax.swing.GroupLayout.PREFERRED_SIZE, 201,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(60, 60, 60)))
);
javax.swing.GroupLayout layout = new
javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 400, Short.MAX_VALUE)
.addGroup(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)
.addGap(0, 300, Short.MAX_VALUE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jPanel1,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
pack();
}// </editor-fold>
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
DCMUpload dialog = new DCMUpload(new
javax.swing.JFrame(), true);
dialog.addWindowListener(new
java.awt.event.WindowAdapter() {
public void
windowClosing(java.awt.event.WindowEvent e) {
System.exit(0);
}
});
dialog.setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JButton cancelButton;
private javax.swing.JLabel jLabel1;
private javax.swing.JPanel jPanel1;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JTable tableDCM;
private javax.swing.JButton uploadButton;
// End of variables declaration
}