Tenho um Jframe bunitinho… com o JMenubar…
enfim… ao clicar em um JMenuItem eu pegaria o JPanel q tem e acrscentaria alguns objetos (como: JTextArea, JButton, etc)
só q na hora da execução ele naum aparece… acho q naum atualiza o JPanel… como resolvo isso???
Segue abaixo um exemplo do Código do Evento.
[code] private void InserirActionPerformed(java.awt.event.ActionEvent evt) {
panel2 = super.getContentPane();
TextArea teste = new TextArea("Teste");
panel2.add(teste);
}[/code]
Oi
Italo, experimente colocar um show no final desse código.
show();
T+
hehehe sou muito iniciante mesmo… hauhauahuahua
Brigado Funcionou!!!
mas deu outro problema…
ele atualiza o JPanel legalzinho… mas se eu tentar acessar o MENU (JMenu) ele naum aparece… tipo eu clicko… aparece ele como clikado… mas naum aparece os JMenuItem…

Oi
Italo, aí nesse outro problema deve ser algum problema com a lógica de montagem de tua interface… se quiseres postar o código poderemos analisa-lo e descobrir o problema.
T+
Opa ta ai o código… é só a titulo de aprendizagem… naum é nada demais…
to usando o NETBEANS 3.6
[code]/*
- pedido.java
-
- Created on 10 de Maio de 2004, 08:44
*/
import java.awt.*;
public class pedido extends javax.swing.JFrame {
Container panel2;
public pedido() {
initComponents();
}
private void initComponents() {
Panel = new javax.swing.JPanel();
BarraMenu = new javax.swing.JMenuBar();
Pedido = new javax.swing.JMenu();
Inserir = new javax.swing.JMenuItem();
Consulta = new javax.swing.JMenuItem();
Alterar = new javax.swing.JMenuItem();
jSeparator1 = new javax.swing.JSeparator();
jMenuItem1 = new javax.swing.JMenuItem();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle("Controle de Entregas");
addWindowListener(new java.awt.event.WindowAdapter() {
public void windowClosing(java.awt.event.WindowEvent evt) {
exitForm(evt);
}
});
Panel.setLayout(null);
Panel.setPreferredSize(new java.awt.Dimension(600, 400));
getContentPane().add(Panel, java.awt.BorderLayout.CENTER);
Pedido.setMnemonic('P');
Pedido.setLabel("Pedido");
Inserir.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_I, java.awt.event.InputEvent.CTRL_MASK));
Inserir.setMnemonic('I');
Inserir.setText("Inserir");
Inserir.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
InserirActionPerformed(evt);
}
});
Pedido.add(Inserir);
Consulta.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_C, java.awt.event.InputEvent.CTRL_MASK));
Consulta.setMnemonic('C');
Consulta.setText("Consulta/Exclui");
Pedido.add(Consulta);
Alterar.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_A, java.awt.event.InputEvent.CTRL_MASK));
Alterar.setMnemonic('A');
Alterar.setText("Alterar");
Pedido.add(Alterar);
Pedido.add(jSeparator1);
jMenuItem1.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_X, java.awt.event.InputEvent.CTRL_MASK));
jMenuItem1.setMnemonic('r');
jMenuItem1.setText("Sair");
jMenuItem1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jMenuItem1ActionPerformed(evt);
}
});
Pedido.add(jMenuItem1);
BarraMenu.add(Pedido);
setJMenuBar(BarraMenu);
pack();
}
private void InserirActionPerformed(java.awt.event.ActionEvent evt) {
panel2 = super.getContentPane();
Button teste = new Button("nome");
panel2.add(teste);
show();
}
private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {
System.exit(0);
}
private void exitForm(java.awt.event.WindowEvent evt) {
System.exit(0);
}
public static void main(String args[]) {
new pedido().show();
}
// Variables declaration - do not modify
private javax.swing.JMenuItem Alterar;
private javax.swing.JMenuBar BarraMenu;
private javax.swing.JMenuItem Consulta;
private javax.swing.JMenuItem Inserir;
private javax.swing.JPanel Panel;
private javax.swing.JMenu Pedido;
private javax.swing.JMenuItem jMenuItem1;
private javax.swing.JSeparator jSeparator1;
// End of variables declaration
}
[/code]
Já descobri o q é já…
O Jpanel tá ficando por cima do JMENUITEM… provavelmente por problemas de lógica… mas como posso arrumar isso???
Oi
Iatalo, cara aí no meu caso é só testando, não sou muito bom com GUI cara… Tente colocar o show em algum objeto especifico ou direto na classe… Aí não sei bem… agora é a hora de testar… :oops:
T+
Que tal colocar um Nome_do_painel.setVisible(true);
