elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Recuerda que debes registrarte en el foro para poder participar (preguntar y responder)


+  Foro de elhacker.net
|-+  Programación
| |-+  Programación General
| | |-+  Java
| | | |-+  [JAVA] JPanel y JButton
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] 2 Ir Abajo Respuesta Imprimir
Autor Tema: [JAVA] JPanel y JButton  (Leído 6,926 veces)
maikmilk

Desconectado Desconectado

Mensajes: 26



Ver Perfil
[JAVA] JPanel y JButton
« en: 30 Abril 2013, 15:34 pm »

Tengo un problema y es el siguiente.
Uso NeatBeans como IDE y estoy creando una aplicación de escritorio mendiante el editor que ofrece NeatBeans.

He creado un JFrame de un tamaño de 500*400 y sobre ese JFrame añado un JPanle de 500*400 con un textfield y dos botones que al presionarlos llaman a otro JPanel implementado en el mismo paquete tambien atraves del editor de NeatBeans. En este JPanel coloco una serie de cajas de texto, etiquetas,botones etc... , y aqui surge el problema y es que el JPanel se muestra pero lo que no se muestra son los botones, etiquetas y de mas que he añadido mediante el editor.

Cual podría ser el problema?

Adjunto codigo

Código:
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package aplicacionindemnizaciones.vista;

/**
 *
 * @author Miki
 */
public class Principal extends javax.swing.JFrame {

    /**
     * Creates new form Principal
     */
    public Principal() {
        initComponents();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">                         
    private void initComponents() {

        PanelPrincipal = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        PanelPrincipal.setPreferredSize(new java.awt.Dimension(500, 400));

        jLabel1.setFont(new java.awt.Font("Apple Chancery", 1, 36)); // NOI18N
        jLabel1.setForeground(new java.awt.Color(255, 0, 51));
        jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel1.setText("Aplicación FOL");

        jButton1.setText("Calculo Indemnizaciones");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jButton2.setText("Calculo Nominas");

        org.jdesktop.layout.GroupLayout PanelPrincipalLayout = new org.jdesktop.layout.GroupLayout(PanelPrincipal);
        PanelPrincipal.setLayout(PanelPrincipalLayout);
        PanelPrincipalLayout.setHorizontalGroup(
            PanelPrincipalLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jLabel1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .add(PanelPrincipalLayout.createSequentialGroup()
                .add(147, 147, 147)
                .add(PanelPrincipalLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false)
                    .add(jButton1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .add(jButton2, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap(152, Short.MAX_VALUE))
        );
        PanelPrincipalLayout.setVerticalGroup(
            PanelPrincipalLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(PanelPrincipalLayout.createSequentialGroup()
                .add(80, 80, 80)
                .add(jLabel1)
                .add(51, 51, 51)
                .add(jButton1)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                .add(jButton2)
                .addContainerGap(108, Short.MAX_VALUE))
        );

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(PanelPrincipal, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(org.jdesktop.layout.GroupLayout.TRAILING, PanelPrincipal, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 367, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>                       

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         
        // TODO add your handling code here:
        Indemnizaciones i = new Indemnizaciones();
        getContentPane().add(i);
        i.setVisible(true);
        PanelPrincipal.setVisible(false);
        i.setVisible(true);
    }                                       

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(Principal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(Principal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(Principal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(Principal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new Principal().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify                     
    public static javax.swing.JPanel PanelPrincipal;
    public static javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JLabel jLabel1;
    // End of variables declaration                   
}

Código:
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package aplicacionindemnizaciones.vista;

/**
 *
 * @author Miki
 */
public class Indemnizaciones extends javax.swing.JPanel {

    /**
     * Creates new form Indemnizaciones
     */
    public Indemnizaciones() {
        initComponents();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">                         
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jTextField2 = new javax.swing.JTextField();
        Antigüedad = new javax.swing.JLabel();
        intAnyo = new javax.swing.JComboBox();
        jLabel4 = new javax.swing.JLabel();
        jTextField3 = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        jTextField4 = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        jTextField5 = new javax.swing.JTextField();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        jLabel10 = new javax.swing.JLabel();
        jButton1 = new javax.swing.JButton();
        jTextField6 = new javax.swing.JTextField();

        jLabel3.setText("Salario Base:");

        Antigüedad.setText("Antigüedad");

        intAnyo.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "2008", "2009", "2010", "2011", "2012", "2013" }));
        intAnyo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                intAnyoActionPerformed(evt);
            }
        });

        jLabel4.setText("Pluses:");

        jLabel5.setText("Pagas extraordinarias:");

        jLabel6.setText("Vacaciones disfrutadas:");

        jLabel7.setText("€");

        jLabel8.setText("días");

        jLabel9.setText("€");

        jLabel10.setText("€");

        jButton1.setText("Calcular");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jTextField6.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextField6ActionPerformed(evt);
            }
        });

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(layout.createSequentialGroup()
                        .add(20, 20, 20)
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(layout.createSequentialGroup()
                                .add(jLabel3)
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                .add(jTextField2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 82, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                .add(jLabel7)
                                .add(18, 18, 18)
                                .add(Antigüedad)
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                .add(intAnyo, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                            .add(layout.createSequentialGroup()
                                .add(jLabel4)
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                .add(jTextField3, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 56, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                .add(jLabel9)
                                .add(18, 18, 18)
                                .add(jLabel5)
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                .add(jTextField4, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 94, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                .add(jLabel10))
                            .add(layout.createSequentialGroup()
                                .add(jLabel6)
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                .add(jTextField5, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 40, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                .add(jLabel8))))
                    .add(layout.createSequentialGroup()
                        .add(110, 110, 110)
                        .add(jButton1)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(jTextField6, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 93, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
                .add(22, 22, 22))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .add(14, 14, 14)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel3)
                    .add(jTextField2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(jLabel7)
                    .add(Antigüedad)
                    .add(intAnyo, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel4)
                    .add(jTextField3, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(jLabel9)
                    .add(jLabel5)
                    .add(jTextField4, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(jLabel10))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel6)
                    .add(jTextField5, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(jLabel8))
                .add(18, 18, 18)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jButton1)
                    .add(jTextField6, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(12, Short.MAX_VALUE))
        );
    }// </editor-fold>                       

    private void intAnyoActionPerformed(java.awt.event.ActionEvent evt) {                                       
        // TODO add your handling code here:
    }                                       

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         
        // TODO add your handling code here:
    }                                       

    private void jTextField6ActionPerformed(java.awt.event.ActionEvent evt) {                                           
        // TODO add your handling code here:
    }                                           

    // Variables declaration - do not modify                     
    private javax.swing.JLabel Antigüedad;
    private javax.swing.JComboBox intAnyo;
    private javax.swing.JButton jButton1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JTextField jTextField2;
    private javax.swing.JTextField jTextField3;
    private javax.swing.JTextField jTextField4;
    private javax.swing.JTextField jTextField5;
    private javax.swing.JTextField jTextField6;
    // End of variables declaration                   
}


En línea

dennis094

Desconectado Desconectado

Mensajes: 185


Embrace your dreams, protect your honor


Ver Perfil
Re: [JAVA] JPanel y JButton
« Respuesta #1 en: 30 Abril 2013, 23:14 pm »

El codigo es demasiado largo para mirarlo ahora mismo ya que ha perdido el madrid y no estoy de animo...  :-\ jajajja pero bueno

Asi a primera vista no encuentro nada raro, pero tendria que mirarlo mas, lo que puede ser, es que al crear un jFrame de 500*800 y un jPanel del mismo tamaño, si luego creas otro jPanel, este no se va a mostrar ya que no tiene espacio suficiente en el Frame.

Prueba a cambiar el tamaño .

Si no se arregla con eso vuelve a escribir y ya miro el codigo en profundidad.
Un saludoo


En línea

sapito169


Desconectado Desconectado

Mensajes: 628



Ver Perfil
Re: [JAVA] JPanel y JButton
« Respuesta #2 en: 1 Mayo 2013, 00:25 am »

desistala netbeans
agarra algun libro o tutorial y ponte a estudiar y tus problemas estaran resueltos
En línea

visualfree

Desconectado Desconectado

Mensajes: 201


Ver Perfil
Re: [JAVA] JPanel y JButton
« Respuesta #3 en: 1 Mayo 2013, 05:59 am »

+1 sapito169.
En línea

sapito169


Desconectado Desconectado

Mensajes: 628



Ver Perfil
Re: [JAVA] JPanel y JButton
« Respuesta #4 en: 1 Mayo 2013, 15:49 pm »

tu primera lección es que nadie entiende el código creado por netbean si te dice que lo entiende es que te esta mintiendo

nadie en su sano juicio intentara usar el código creado por netbeans por que es horrible

1 creas un jframe
2 le pones al jframe un BorderLayaut
3 creas tu Jpanel
4 agregas tu jpanel con BorderLayaut.CENTER al JFrame

lo que he explicado lo puedes hacer a mano o con netbeans o con cualquier ide es mas con block de notas

si te suena a chino los pasos que te di es que no estudiaste bien
En línea

maikmilk

Desconectado Desconectado

Mensajes: 26



Ver Perfil
Re: [JAVA] JPanel y JButton
« Respuesta #5 en: 2 Mayo 2013, 02:36 am »

A ver gente la pregunta es como hacerlo con neatbeans lo que quiero hacer ya lo e hecho sin usar neatbeans, deberías centrarse más en contestar a las preguntas que a suponer que no se hacer algo que de sobra se hacer.
En línea

sapito169


Desconectado Desconectado

Mensajes: 628



Ver Perfil
Re: [JAVA] JPanel y JButton
« Respuesta #6 en: 2 Mayo 2013, 15:20 pm »

entonces ponte un vídeo tutorial en youtube

ahora ya sabes por que netbeans apesta la única forma de corregir tu error es ir hasta tu casa mirarte del hombro y darte un sopapo cuando cometiste un error para luego corregir te

tu única esperanza es que o mires vídeo tutoriales donde creen interfaces de usuario en youtube

o busques a alguien que vaya a tu casa a darte un sopapo cuando vea que cometiste un error

a propósito me ofrezco como voluntario para ir asta tu casa para cor regirte si me pagas los pasajes
« Última modificación: 2 Mayo 2013, 15:30 pm por sapito169 » En línea

maikmilk

Desconectado Desconectado

Mensajes: 26



Ver Perfil
Re: [JAVA] JPanel y JButton
« Respuesta #7 en: 2 Mayo 2013, 18:31 pm »

entonces ponte un vídeo tutorial en youtube

ahora ya sabes por que netbeans apesta la única forma de corregir tu error es ir hasta tu casa mirarte del hombro y darte un sopapo cuando cometiste un error para luego corregir te

tu única esperanza es que o mires vídeo tutoriales donde creen interfaces de usuario en youtube

o busques a alguien que vaya a tu casa a darte un sopapo cuando vea que cometiste un error

a propósito me ofrezco como voluntario para ir asta tu casa para cor regirte si me pagas los pasajes

No entiendo? Bueno gracias por la NO ayuda
En línea

0xFer


Desconectado Desconectado

Mensajes: 400



Ver Perfil
Re: [JAVA] JPanel y JButton
« Respuesta #8 en: 2 Mayo 2013, 20:55 pm »

por que no creas en vez de un panel,un Frame nuevo
En línea

Código
  1. int getRandomNumber(){
  2.    return 4; //chosen by fair dice roll
  3.              //guaranteed to be random
  4. }
YairMon

Desconectado Desconectado

Mensajes: 15



Ver Perfil
Re: [JAVA] JPanel y JButton
« Respuesta #9 en: 19 Mayo 2013, 22:57 pm »

Tienen razon!!... ¿Por que razon vienes aqui a postear codigo (horrible) de netBeans?

Solo haz un frame y un panel y pon el boton

 :xD  

deja la pereza >_<

PD. Muy claramente dice en las reglas que no es obligacion de nadie responder las preguntas

PD2: Pon en el metodo paint(graphics g) al final "super.paintcomponents(g)"


« Última modificación: 19 Mayo 2013, 23:00 pm por YairMon » En línea

Páginas: [1] 2 Ir Arriba Respuesta Imprimir 

Ir a:  

Mensajes similares
Asunto Iniciado por Respuestas Vistas Último mensaje
Ayuda con un jButton
Java
kapotnt 6 7,290 Último mensaje 4 Septiembre 2008, 18:07 pm
por CorazonValiente
evento de un JButton
Java
brian_e 6 9,066 Último mensaje 27 Abril 2009, 16:25 pm
por Amerikano|Cls
JAVA ECLIPSE ==>DAR EVENTO CLIK AL JButton
Java
leliCabello 1 5,370 Último mensaje 11 Octubre 2009, 02:22 am
por egyware
Redimensionar tamaño JPanel dentro de otro JPanel [SOLUCIONADO]
Java
pisagatos 3 21,470 Último mensaje 11 Octubre 2012, 04:16 am
por Gianko
duda con java jpanel y html
Java
abi-ds 2 2,979 Último mensaje 20 Agosto 2012, 20:37 pm
por Debci
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines