E ae galera, blz?
To com o seguinte problema.
O painel q eu uso pra criar uma tela default pro meu sistema soh aparece no frame depois q eu mexo no tamanho dele :shock:
Enquanto eu naum redimencionar o frame, ele naum aparece!
Alguem sabe o pq disso?
segue as classes:
import javax.swing.*;
import java.awt.*;
public class DefaultGUI extends JPanel {
private JTextField[] fields;
private JLabel[] labels;
private JButton[] buttons;
private final static String[] names = { "Número de Registro", "Nome", "E-mail",
"Tel Residencial", "Tel Comercial", "Celular", "Fax" };
public DefaultGUI()
{
JPanel container = new JPanel();
container.setLayout ( new GridLayout ( 9, 2, 5, 5 ) );
labels = new JLabel [ 7 ];
fields = new JTextField [ 7 ];
for ( int i = 0; i < labels.length; i++ ) {
labels [ i ] = new JLabel ( names [ i ] );
fields [ i ] = new JTextField ( 10 );
container.add ( labels [ i ] );
container.add ( fields [ i ] );
}
buttons = new JButton [ 4 ];
for ( int i = 0; i < buttons.length; i++ ) {
buttons [ i ] = new JButton ( "B" + i );
container.add ( buttons [ i ] );
}
add ( container );
validate();
setVisible ( true );
}
protected void clearFields()
{
for ( int i = 0; i < fields.length; i++ )
fields [ i ].setText ( "" );
}
protected String[] getFieldValues()
{
String[] values = new String [ fields.length ];
for ( int i = 0; i < fields.length; i++ )
values [ i ] = fields [ i ].getText();
return values;
}
}
//Classe de texte abaixo :
import javax.swing.*;
public class Teste extends JFrame {
private DefaultGUI gui;
public Teste()
{
gui = new DefaultGUI();
getContentPane().add ( gui );
setVisible ( true );
setSize ( 400, 400 );
}
public static void main ( String[] args )
{
new Teste();
}
}