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;
}
}

