944,016 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Unsolved
  • Views: 1867
  • Java RSS
Nov 10th, 2009
0

Problem with GUI!

Expand Post »
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:


Java Syntax (Toggle Plain Text)
  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!
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
denni2727 is offline Offline
6 posts
since Nov 2009
Nov 10th, 2009
0
Re: Problem with GUI!
Try adding a revalidate() and possibly a repaint() in your runnable after you set the new screen.
Moderator
Featured Poster
Reputation Points: 3239
Solved Threads: 839
Posting Genius
Ezzaral is offline Offline
6,761 posts
since May 2007
Nov 11th, 2009
0

I did it!!!!

Click to Expand / Collapse  Quote originally posted by Ezzaral ...
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.!!
Reputation Points: 10
Solved Threads: 0
Newbie Poster
denni2727 is offline Offline
6 posts
since Nov 2009

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: web audio stream and jmf
Next Thread in Java Forum Timeline: how to check the value in a TextField if it is equel to specific string ?





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC