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:

// Class Search
table = bd.getPreparedJTable(sentencia);

public JTable getPreparedJTable(String sentencia)
	{
		JTable table = null;
		
		try
		{
			startConnection();
			prepararStatement();
	
			Vector columnNames = new Vector();
			Vector data = new Vector();
 
			    setResultSet(getStatement().executeQuery(sentencia));
             ResultSetMetaData md = getResultSet().getMetaData();
            int columns = md.getColumnCount();
 
            //  Get column names
 
            for (int i = 1; i <= columns; i++)
            {
                columnNames.addElement( md.getColumnName(i) );
            }
 
            //  Get row data
 
            while (getResultSet().next())
            {
                Vector row = new Vector(columns);
 
                for (int i = 1; i <= columns; i++)
                {
                    row.addElement( getResultSet().getObject(i) );
                }
 
                data.addElement( row );
            }
 
            getResultSet().close();
			getStatement().close();
			closeConnection();

 
        //  Create table with database data
 
        table = new JTable(data, columnNames)
		{
			public boolean isCellEditable(int row, int col){
							return false;
						
						}
		
		};
		
		}
		catch(SQLException e)
		{
			e.printStackTrace();
		}
		
		return table;
	}

// And this is how i change the background of my JFrame


void setPanel(final JPanel screen)
	{
		try{
			SwingUtilities.invokeLater( new Runnable(){
				
				public void run()
				{
					getContentPane().removeAll();
					setContentPane(screen);
				}
			});
		}
		catch(Exception e)
		{
			e.printStackTrace();
		}
		SwingUtilities.updateComponentTreeUI(this);
	}

Any help would be appreciated!

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.!!

This article has been dead for over six months. Start a new discussion instead.