2015-12-02 42 views
1

我的应用程序故障每次执行表模型的更新,正如我们在第一张图片中看到的,我使用数字1进行查询,它会返回表中结果集的数据,图片2,我做了一个新的查询,现在用数字2,它似乎工作,但是当我滚动水平表时,jtable似乎崩溃并重新重新绘制第一个查询。更新内容时Jtable故障

public GUIDetalleActividades(String cedula) { 
     this.cedula = cedula; 
     setTitle("Detalle Actividades"); 
     setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 
     setBounds(100, 100, 597, 500); 
     contentPane = new JPanel(); 
     contentPane.setBorder(new EmptyBorder(5, 5, 5, 5)); 
     setContentPane(contentPane); 
     contentPane.setLayout(null); 

     JLabel lblAContinuacinSe = new JLabel(
       "A continuaci\u00F3n se muestra un listado con todos los proyectos a su cargo, en el siguiente campo podr\u00E1 consultar"); 
     lblAContinuacinSe.setBounds(10, 11, 570, 14); 
     contentPane.add(lblAContinuacinSe); 

     JLabel lblParaVerLos = new JLabel("las actividades de un determinado proyecto"); 
     lblParaVerLos.setBounds(10, 29, 407, 14); 
     contentPane.add(lblParaVerLos); 

     //creating upper table with resultset 

     table = new JTable(cons.tablaConsultaProyectosACargo(cedula)); 

     JScrollPane scrollPane = new JScrollPane(table, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, 
       JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); 
     scrollPane.setBounds(21, 86, 539, 134); 

     contentPane.add(scrollPane); 
     table.getColumnModel().getColumn(1).setPreferredWidth(100); 
     table.getColumnModel().getColumn(2).setPreferredWidth(100); 
     table.getColumnModel().getColumn(3).setPreferredWidth(100); 
     table.getColumnModel().getColumn(4).setPreferredWidth(100); 

     scrollPane.setViewportView(table); 

     JLabel lblConsultarActividadNoproyecto = new JLabel("Consultar actividad No.proyecto:"); 
     lblConsultarActividadNoproyecto.setBounds(21, 244, 174, 14); 
     contentPane.add(lblConsultarActividadNoproyecto); 

     txtnum = new JTextField(); 
     txtnum.setBounds(192, 241, 86, 20); 
     contentPane.add(txtnum); 
     txtnum.setColumns(10); 

     JButton btnConsultar = new JButton("Consultar"); 
     btnConsultar.addActionListener(new ActionListener() { 
      public void actionPerformed(ActionEvent arg0) { 

       //pressing the button should repaint the table with new data and no glitches 
       showtable2(txtnum.getText()); 
      } 
     }); 
     btnConsultar.setBounds(301, 240, 89, 23); 
     contentPane.add(btnConsultar); 

    } 

    //creating table with default table model sent from the class that does all the queries 
    public void showtable2(String num) { 

     table_1 = new JTable(cons.tablaConsultaActividades(num)); 
     table_1.setEnabled(false); 
     JScrollPane scrollPane_1 = new JScrollPane(table_1, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, 
       JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); 
     scrollPane_1.setBounds(20, 310, 552, 134); 
     table_1.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); 
     contentPane.add(scrollPane_1); 
     table_1.getColumnModel().getColumn(1).setPreferredWidth(100); 
     table_1.getColumnModel().getColumn(2).setPreferredWidth(100); 
     table_1.getColumnModel().getColumn(3).setPreferredWidth(100); 
     table_1.getColumnModel().getColumn(4).setPreferredWidth(100); 

     scrollPane_1.setViewportView(table_1); 

    } 

    public String getCedula() { 
     return cedula; 
    } 

    public void setCedula(String cedula) { 
     this.cedula = cedula; 
    } 
} 

enter image description here

enter image description here

enter image description here

+0

*在第一张图片*你忘了张贴图片... – Frakcool

+0

是的抱歉上传它,stackoverflow不会让我手动添加它 –

+1

发布的链接,我们可以编辑它们让他们显示 – Frakcool

回答

0

所以,问题是在虚空showtable2,从来没有重新创建scrollpanel的字段或表的模式,只是delcare他们一次,更新表的模型与table.setmodel