我正在开发一个Java JFrame应用程序
JTextField
JTable
在中存储在数据库中的文本字段数据,并通过表格显示。
它从数据库成功显示数据。但问题是当我最小化表格数据每次都消失时。即使用户最小化框架,是否还有显示数据的选项?
或者,有没有其他方法可以解决这个问题?
public void insertTaskDetail(){
global.dbConnect();
String insertkeydetail = "{call sp_inserttaskdetail(?,?,?,?)}";
try{
CallableStatement callableStatement;
callableStatement = global.con.prepareCall(insertkeydetail);
System.out.println("Stored Procedure Insert Key Detail is Called");
String dt=global.getCurrentDateTime();
System.out.println(dt);
callableStatement.setString("p1", jText_Task_Name.getText().toString());
callableStatement.setString("p2", dt);
callableStatement.setString("p3", "0");
callableStatement.setString("p4", L_Id);
callableStatement.executeUpdate();
System.out.println("Task Detail is successfully inserted in database");
global.con.commit();
showtask();
}catch (Exception e){
System.out.println("Sql Exception Add Task Changed:"+e.toString());
}
}
public void showtask(){
global.dbConnect();
String showtask = "{call sp_showtask(?,?)}";
try{
callableStatement = global.con.prepareCall(showtask, ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
System.out.println("Stored Procedure Get Task Detail is Called");
callableStatement.setString("p1", L_Id);
callableStatement.setString("p2", "false");
rs=callableStatement.executeQuery();
System.out.println(rs.toString());
//Task , Start Time , Finish Time , Completed
String task, st;
boolean cmp;
int i=0;
while(rs.next()){
i++;
}
data=new Object[i][];
int j=0;
rs.first();
if(i>0){
do{
System.out.println(i);
task=rs.getString("Task");
System.out.println(task);
st=rs.getString("Start Time");
cmp=rs.getBoolean("Completed");
data[j] = new Object[]{task, st, cmp};
j++;
}while(rs.next());
}
}catch (SQLException e){
System.out.println("Sql Exception:"+e.toString());
}
jText_Task_Name.setText("");
TableDataModel();
}
public void TableDataModel(){
String[] cols = {"<html>Task<br>Name</html>", "<html>Start<br>Time</html>", "Finished"};
model = new DefaultTableModel(data, cols){
@Override
public Class<?> getColumnClass(int col){
return col == 2 ? Boolean.class : String.class;
}
@Override
public boolean isCellEditable(int row, int column){
return column==2 ? true : false;
}
};
table = new JTable(model){
@Override
public boolean isCellEditable(int row, int column) {
return column==2 ? true : false;
}
};
table.setFont(new java.awt.Font("Times New Roman", 0, 14));
table.getTableHeader().setFont(new java.awt.Font("Times New Roman", 0, 14));
table.getTableHeader().enable(false);
JCheckBox jcheckBox=new JCheckBox();
TableColumnModel columnModel = table.getColumnModel();
System.out.println("Column Model:"+columnModel.toString());
columnModel.getColumn(2).setCellEditor(new DefaultCellEditor(jcheckBox));
jcheckBox.addChangeListener(new ChangeListener(){
@Override
public void stateChanged(ChangeEvent e){
int rowCount = model.getRowCount();
for(int i=0; i<rowCount; i++){
Boolean selected = (Boolean)model.getValueAt(i, 2);
if(selected != null && selected){
System.out.println("Removed:"+i);
model.removeRow(i);
i--;
}
}
}
});
JScrollPane jScrollpane=new JScrollPane(table);
jScrollpane.setViewportView(table);
this.add(jScrollpane);
jScrollpane.setFont(new java.awt.Font("Times New Roman", 0, 14));
jScrollpane.setBounds(10, 130, 295, 190);
call++;
}