Guest User

Untitled

a guest
Aug 10th, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.96 KB | None | 0 0
  1. Database data doesn't fill into JTable
  2. private Object[][] notes = null;
  3. setUpStatusColumn(noteTable, noteTable.getColumnModel().getColumn(2));
  4.  
  5. protected JTable createTable(GradesModel gradesModel) {
  6. return new JTable(gradesModel);
  7. }
  8.  
  9. public void setUpStatusColumn(JTable table, TableColumn statusColumn) {
  10.  
  11. statusCombo = new JComboBox();
  12. statusCombo.addItem("OTOCLOSED");
  13. statusCombo.addItem("INPROGRESS");
  14. statusCombo.addItem("OPEN");
  15. statusCombo.addItem("CLOSED");
  16. statusColumn.setCellEditor(new DefaultCellEditor(statusCombo));
  17.  
  18. DefaultTableCellRenderer renderer = new DefaultTableCellRenderer();
  19. renderer.setToolTipText("Click to select Note Status");
  20. statusColumn.setCellRenderer(renderer);
  21.  
  22. }
  23.  
  24. private class GradesModel extends AbstractTableModel {
  25.  
  26. public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
  27.  
  28. notes[rowIndex][columnIndex] = aValue;
  29. fireTableCellUpdated(rowIndex, columnIndex);
  30. }
  31.  
  32. public void addTableModelListener(TableModelListener l) {
  33. }
  34.  
  35. public void removeTableModelListener(TableModelListener l) {
  36. }
  37.  
  38. public boolean isCellEditable(int rowIndex, int columnIndex) {
  39. if (columnIndex == 0 || columnIndex == 1 || columnIndex == 4 || columnIndex == 5)
  40. return false;
  41. else
  42. return true;
  43.  
  44. }
  45.  
  46. public Class<?> getColumnClass(int col) {
  47. switch (col) {
  48. case 0:
  49. case 1:
  50. case 2:
  51. case 3:
  52. case 4:
  53. case 5:
  54. return String.class;
  55. }
  56.  
  57. throw new AssertionError("invalid column");
  58. }
  59.  
  60. public int getRowCount() {
  61. return notes.length;
  62. }
  63.  
  64. public int getColumnCount() {
  65. return 6;
  66. }
  67.  
  68. public String getColumnName(int col) {
  69. switch (col) {
  70. case 0:
  71. return "ETT Date";
  72. case 1:
  73. return "Control Name";
  74. case 2:
  75. return "Note Status Type";
  76. case 3:
  77. return "Note Log Desc";
  78. case 4:
  79. return "Note Log Date Time";
  80. case 5:
  81. return "Update/Insert";
  82. }
  83.  
  84. throw new AssertionError("invalid column");
  85. }
  86.  
  87. public Object getValueAt(int row, int col) {
  88.  
  89. for (int i = 0; i < 6; i++) {
  90. if (col == i)
  91. return notes[row][col];
  92. }
  93.  
  94. throw new AssertionError("invalid column");
  95. }
  96.  
  97.  
  98. }
  99.  
  100. public void getTableData() throws Exception {
  101. Vector<AlarmLog> alarmLog = null;
  102. alarmLog = RepositoryHandler.getGlobalRepository().getAlarmLog(
  103. alarmId);
  104.  
  105. notes = new Object[alarmLog.size() ][5];
  106. java.util.Iterator<AlarmLog> ite = alarmLog.iterator();
  107. int i = 0;
  108.  
  109. GradesModel myModel=(GradesModel)noteTable.getModel();
  110.  
  111. while(ite.hasNext()){
  112. AlarmLog aLog = ite.next();
  113. myModel.setValueAt(aLog.getEttDate(), i, 0);
  114. myModel.setValueAt(aLog.getControlName(), i, 1);
  115. myModel.setValueAt(aLog.getAlarmStatusType(), i, 2);
  116. myModel.setValueAt(aLog.getAlarmLogDesc(), i, 3);
  117. myModel.setValueAt(aLog.getAlarmLogDateTime(), i, 4);
  118. myModel.setValueAt(1, i, 5);
  119. i++;
  120. }
  121. // fill table code
  122. noteTable.repaint();
  123.  
  124. //setModel
  125.  
  126. }
  127. public void getDataFromTable() {
  128. int columnCount = noteTable.getModel().getColumnCount();
  129. int rowCount = noteTable.getModel().getRowCount();
  130. Object[][] objArray = new Object[rowCount][columnCount];
  131. for (int i = 0; i < rowCount; i++) {
  132. for (int j = 0; j < columnCount; j++) {
  133. objArray[i][j] = noteTable.getModel().getValueAt(i, j);
  134. }
  135. }
  136. }
Add Comment
Please, Sign In to add comment