Problem to return a JScrollPane into a JPanel (search engine with SQL)

i make a search engine with SQL, but i cant return the result to JPanel on the ProcEmployer class :(

There is any problem to do this ?

publicclass ProcEmployerextends JInternalFrameimplements ActionListener{

privatestaticfinallong serialVersionUID = -1237537304008263064;

private JLabel lblName;

private JTextField txtName;

private JLabel lblRG;

private JTextField txtRG;

private JLabel lblCPF;

private JTextField txtCPF;

private JButton bSearch;

private JPanel resultSearch;

private JPanel buttons;

private JPanel form;

public ProcEmployer(){

super("Search Employer",true,true,true,true);

this.setSize(500, 150);

this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);

this.getContentPane().setLayout(new BorderLayout());

lblName =new JLabel("Name");

txtName =new JTextField("");

lblRG =new JLabel("RG");

txtRG =new JTextField("");

lblCPF =new JLabel("CPF");

txtCPF =new JTextField("");

bSearch =new JButton("Search");

bProcurar.addActionListener(this);

form =new JPanel(new GridLayout(3, 2));

txtName.requestFocus();//mantem o focus no nome

form.add(lblName);

form.add(txtName);

form.add(lblRG);

form.add(txtRG);

form.add(lblCPF);

form.add(txtCPF);

buttons =new JPanel(new FlowLayout());

buttons.add(bProcurar);

resultSearch =new JPanel(new FlowLayout());

this.getContentPane().add(form, BorderLayout.NORTH);

this.getContentPane().add(buttons, BorderLayout.CENTER);

this.getContentPane().add(resultSearch, BorderLayout.SOUTH);

}

publicvoid actionPerformed(ActionEvent e){

if (e.getActionCommand().equals("Search")){

resultSearch.add(

EmployerSQL.Procurar(txtName.getText(),

txtRG.getText(),

txtCPF.getText()

)

);

this.getContentPane().add(resultSearch, BorderLayout.SOUTH);

JOptionPane.showMessageDialog(this,"OK");

}else{

JOptionPane.showMessageDialog(this,"Cancel");

}

}

}

class EmployerSQL:

publicclass EmployerSQL{

staticfinal String JDBC_DRIVER ="org.hsqldb.jdbcDriver";

staticfinal String DATABASE_URL ="jdbc:hsqldb:file:/path_to_db/sysstock";

staticfinal String USERNAME="sa";

staticfinal String PASSWORD="";

publicstatic JScrollPane Procurar(String name,

String RG,

String CPF

){

final String DEFAULT_QUERY ="SELECT * FROM employer";

ResultSetTableModel tableModel =null;

JTable resultTable =null;

try{

tableModel =new ResultSetTableModel( JDBC_DRIVER, DATABASE_URL,USERNAME, PASSWORD, DEFAULT_QUERY );

}catch (SQLException e){

// TODO Auto-generated catch block

e.printStackTrace();

}catch (ClassNotFoundException e){

// TODO Auto-generated catch block

e.printStackTrace();

}

resultTable =new JTable( tableModel );

JScrollPane scrollPane =new JScrollPane();

scrollPane.setMaximumSize(new Dimension(640, 390));

scrollPane.setPreferredSize(new Dimension(640, 390));

scrollPane.getViewport().add( resultTable );

//resultadoProcura.add( scrollPane);

System.out.println("->"+scrollPane);

return scrollPane;

}

}

[6634 byte] By [Eduardo_Augustoa] at [2007-10-2 16:35:03]
# 1
> There is any problem to do this ?you tell us.What is your question specifically?
tjacobs01a at 2007-7-13 17:40:28 > top of Java-index,Desktop,Core GUI APIs...
# 2
i cant show the result of search on the class ProcEmployer...do u understand?
Eduardo_Augustoa at 2007-7-13 17:40:28 > top of Java-index,Desktop,Core GUI APIs...
# 3
> i cant show the result of search on the class> ProcEmployer...do u understand?Why not? That's not a very specific question. Ask us something about the java programming language or about its standard libraries
tjacobs01a at 2007-7-13 17:40:28 > top of Java-index,Desktop,Core GUI APIs...
# 4
explain to how can i show the JScrollPane on the this.getContentPane().add(resultSearch,BorderLayout.SOUTH) inside the public void actionPerformed(ActionEvent e){
Eduardo_Augustoa at 2007-7-13 17:40:28 > top of Java-index,Desktop,Core GUI APIs...
# 5

Don't create a new JTable with the search results. Just replace the model of the existing table with a new model containing the search results. After the new TableModel is created you simple do:

table.setModel( tableModel );

Here is a working example that uses this approach:

http://forum.java.sun.com/thread.jspa?forumID=31&threadID=619826

camickra at 2007-7-13 17:40:28 > top of Java-index,Desktop,Core GUI APIs...