Pessoal,
Não consigo maximizar um JInternalFrame depois do pack(), ele simplesmente não maximiza. Seguem as classes:
//Classe ProcEmployer - essa classe monta o formulario de busca
EmployerSQL to search
public class ProcEmployer extends JInternalFrame implements ActionListener {
private static final long serialVersionUID = -1237537304008263064;
private JLabel lblName;
private JTextField txtName;
private JLabel lblRG;
private JTextField txtRG;
private JLabel lblCPF;
private JTextField txtCPF;
private JButton bSearchr;
private JPanel resultSearch;
private JPanel buttons;
private JPanel form;
private JScrollPane resultScroll = null;
public ProcEmployer(){
super("Search Employer",true,true,true,true);
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");
bSearch.addActionListener(this);
form = new JPanel(new GridLayout(3, 2));
txtName.requestFocus();
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(bSearch);
resultSearch = new JPanel(new FlowLayout());
this.getContentPane().add(form, BorderLayout.NORTH);
this.getContentPane().add(buttons, BorderLayout.CENTER);
}
public void actionPerformed(ActionEvent e){
if (e.getActionCommand().equals("Search")) {
if(resultScroll != null)
resultSearch.remove(resultScroll);
resultScroll = FuncionarioSQL.Searchr(txtName.getText(),txtRG.getText(),txtCPF.getText());
resultSearch.add(resultScroll);
this.getContentPane().add(resultSearch, BorderLayout.SOUTH);
pack();
JOptionPane.showMessageDialog(this, "OK");
} else {
JOptionPane.showMessageDialog(this, "Cancel");
}
}
}
//Classe Layout - essa classe chama o ProcEmployer
public class Layout extends JFrame {
private static final long serialVersionUID = 1;
private JDesktopPane theDesktop;
public Layout() {
super("Project");
JMenuBar bar = new JMenuBar();
JMenu addMenu = new JMenu("Main");
JMenuItem newFrame3 = new JMenu("Employer");
JMenuItem newFrame31 = new JMenuItem("Cadastrar");
JMenuItem newFrame32 = new JMenuItem("Search");
JMenuItem newFrame50 = new JMenuItem("Exit");
JMenuItem newFrame22 = new JMenuItem("About");
addMenu.add(newFrame);
addMenu.add(newFrame3);
addMenu.add(newFrame50);
addMenu2.add(newFrame22);
newFrame3.add(newFrame31);
newFrame3.add(newFrame32);
bar.add(addMenu); // add Add menu to menu bar
bar.add(addMenu2); // add Add menu to menu bar
setJMenuBar(bar); // set menu bar for this application
theDesktop = new JDesktopPane(); // create desktop pane
setContentPane(theDesktop); // add desktop pane to frame
newFrame32.addActionListener(
new ActionListener() {// anonymous inner class
// display new internal win
public void actionPerformed(ActionEvent event){
ProcEmployer panel = new ProcEmployer(); // create new panel
panel.pack();
panel.setVisible(true);
theDesktop.add(panel, BorderLayout.CENTER); // add panel
try {
panel.setMaximum(true);
panel.setSelected(true);
} catch (PropertyVetoException e) {
e.printStackTrace();
}
} // end method actionPerformed
} // end anonymous inner class
); // end call to addActionListener
newFrame50.addActionListener(
new ActionListener() {// anonymous inner class
// display new internal window
public void actionPerformed(ActionEvent event) {
System.exit( 0 ); // Sai da aplicação
} // end method actionPerformed
} // end anonymous inner class
); // end call to addActionListener
newFrame22.addActionListener(
new ActionListener() {// anonymous inner class
// display new internal window
public void actionPerformed(ActionEvent event) {
JOptionPane.showMessageDialog(null,"ver. Alpha","About",JOptionPane.INFORMATION_MESSAGE);
} // end method actionPerformed
} // end anonymous inner class
); // end call to addActionListener
} // end constructor DesktopFrame
} // end class
//classe EmployerSQL - essa classe é chamada pelo ProcEmployer e retorna o resultado da busca pro próprio ProcEmployer (q estende um JInternalFrame)
public class EmployerSQL {
static final String JDBC_DRIVER = "org.hsqldb.jdbcDriver";
static final String DATABASE_URL = "jdbc:hsqldb:file:/path_to_dbl/db";
static final String USERNAME= "sa";
static final String PASSWORD= "";
public static JScrollPane Search(String name,String RG,String CPF){
final String DEFAULT_QUERY = "SELECT * FROM employer WHERE nome LIKE '%"+name+"%'";
ResultSetTableModel tableModel = null;
JTable resultTable = null;
try {
tableModel = new ResultSetTableModel( JDBC_DRIVER, DATABASE_URL,USERNAME, PASSWORD, DEFAULT_QUERY );
} catch (SQLException e) {
e.printStackTrace();
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
resultTable = new JTable( tableModel );
JScrollPane scrollPane = new JScrollPane();
scrollPane.setPreferredSize(new Dimension(768, 390));//<---this is my problem, i dont know how can i maximize the JInternalFrame after the search
scrollPane.getViewport().add( resultTable );
return scrollPane;
}
}