Problem with GUI!

Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Nov 2009
Posts: 3
Reputation: denni2727 is an unknown quantity at this point 
Solved Threads: 0
denni2727 denni2727 is offline Offline
Newbie Poster

Problem with GUI!

 
0
  #1
29 Days Ago
At the moment Im developing a java application but Im having a problem.
Im using a JFrame that takes different JPanels, I mean i change its ContentPane for another JPanel everytime i want to show new information.

Im using a database too, im reading data from it im writing them in a JTable, But... when i try to do this my program freeze and stop working until i minimize and maximize my JFrame.!!

I need help with this.!!

What should i do?, Should i add some Threads??

This is part of the code im using:


  1. // Class Search
  2. table = bd.getPreparedJTable(sentencia);
  3.  
  4. public JTable getPreparedJTable(String sentencia)
  5. {
  6. JTable table = null;
  7.  
  8. try
  9. {
  10. startConnection();
  11. prepararStatement();
  12.  
  13. Vector columnNames = new Vector();
  14. Vector data = new Vector();
  15.  
  16. setResultSet(getStatement().executeQuery(sentencia));
  17. ResultSetMetaData md = getResultSet().getMetaData();
  18. int columns = md.getColumnCount();
  19.  
  20. // Get column names
  21.  
  22. for (int i = 1; i <= columns; i++)
  23. {
  24. columnNames.addElement( md.getColumnName(i) );
  25. }
  26.  
  27. // Get row data
  28.  
  29. while (getResultSet().next())
  30. {
  31. Vector row = new Vector(columns);
  32.  
  33. for (int i = 1; i <= columns; i++)
  34. {
  35. row.addElement( getResultSet().getObject(i) );
  36. }
  37.  
  38. data.addElement( row );
  39. }
  40.  
  41. getResultSet().close();
  42. getStatement().close();
  43. closeConnection();
  44.  
  45.  
  46. // Create table with database data
  47.  
  48. table = new JTable(data, columnNames)
  49. {
  50. public boolean isCellEditable(int row, int col){
  51. return false;
  52.  
  53. }
  54.  
  55. };
  56.  
  57. }
  58. catch(SQLException e)
  59. {
  60. e.printStackTrace();
  61. }
  62.  
  63. return table;
  64. }
  65.  
  66. // And this is how i change the background of my JFrame
  67.  
  68.  
  69. void setPanel(final JPanel screen)
  70. {
  71. try{
  72. SwingUtilities.invokeLater( new Runnable(){
  73.  
  74. public void run()
  75. {
  76. getContentPane().removeAll();
  77. setContentPane(screen);
  78. }
  79. });
  80. }
  81. catch(Exception e)
  82. {
  83. e.printStackTrace();
  84. }
  85. SwingUtilities.updateComponentTreeUI(this);
  86. }

Any help would be appreciated!
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 4,490
Reputation: Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of 
Solved Threads: 517
Moderator
Featured Poster
Ezzaral's Avatar
Ezzaral Ezzaral is offline Offline
Industrious Poster
 
0
  #2
29 Days Ago
Try adding a revalidate() and possibly a repaint() in your runnable after you set the new screen.
Reply With Quote Quick reply to this message  
Join Date: Nov 2009
Posts: 3
Reputation: denni2727 is an unknown quantity at this point 
Solved Threads: 0
denni2727 denni2727 is offline Offline
Newbie Poster

I did it!!!!

 
0
  #3
28 Days Ago
Originally Posted by Ezzaral View Post
Try adding a revalidate() and possibly a repaint() in your runnable after you set the new screen.

Thanks Ezzaral for the help, I added a SwingWorker that reads the data from the database and when it finish looking for the data, it revalidate the JTable and repaint the JFrame.!!
Reply With Quote Quick reply to this message  
Reply

Tags
database, freeze, gui, problem, stop, working

Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC