Búsqueda:



Retroceder   ForoDeJava.com La Comunidad de Java Habla Hispana > Índice > Java Básico

 

Etiquetas
componentes, jpanel

Respuesta
 
Herramientas Buscar en Tema Desplegado
  #1  
Antiguo 28-jul-2010, 17:18
Avatar de slash365
slash365 slash365 está desconectado
Principiante
 
Fecha de Ingreso: julio-2010
País:
Mensajes: 2
Agradecimientos: 0
Le agradecieron 0 veces
Poder de Credibilidad: 0
slash365 no se puede calificar en este momento
Predeterminado Agregar componentes a un JPanel

Quisiera saber porque se ocultan los objetos q quiero ingresar a un JPanel.
En este caso los 2 JRadioButton.
Ademas quisiera q se muestre el borde con otro color.

Aqui mi codigo:

Código:
import javax.swing.*;

public class Cliente extends javax.swing.JFrame {

    JPanel panel = new JPanel();
    JLabel vetiquetas[]= new JLabel[4];
    JTextField vcuadros[]= new JTextField[3];
    JRadioButton vopcion[]= new JRadioButton[2];
    JCheckBox check;
    ButtonGroup grupo= new ButtonGroup();
    
    public Cliente() {
        initComponents();
        CreacionVentana();
    }
public void CreacionVentana(){
    //Caracteristicas de la ventana
    this.setTitle("Registro Cliente");
    this.setSize(350,200); 
    
    this.setDefaultCloseOperation(this.EXIT_ON_CLOSE);
    this.getContentPane().add(panel);
    

    String vtextos[]={"Nombre:","Direccion:","Telefono:","Estado Civil:"};
    int i;
        for(i=0;i<vetiquetas.length;i++){
            vetiquetas[i]=new JLabel(); 
            vetiquetas[i].setText(vtextos[i]); 
            vetiquetas[i].setBounds(10,10+30*i,100,20); 
            this.getContentPane().add(vetiquetas[i]);
        }
    int y;
        for(y=0;y<vcuadros.length;y++){
            vcuadros[y]=new JTextField();
            vcuadros[y].setBounds(80, 10+30*y, 200, 20);
            this.getContentPane().add(vcuadros[y]);
        }
    String vopciones[]={"Soltero","Casado"};
    int z;
        for (z=0;z<vopcion.length;z++){
            vopcion[z]=new JRadioButton(); 
            vopcion[z].setText(vopciones[z]); 
            vopcion[z].setBounds(90+80*z,10+30*y,80,20); 
            this.getContentPane().add(vopcion[z]);
        }
               
            check=new JCheckBox(); 
            check.setText("Con hijos"); 
            check.setBounds(10,10+30*i,200,20); 
            this.getContentPane().add(check);

            grupo.add(vopcion[0]);
            grupo.add(vopcion[1]);
            
            panel.add(vopcion[0]);
            panel.add(vopcion[1]);
Gracias.
Responder Citando
Entre a los Links relacionados
  #2  
Antiguo 29-jul-2010, 15:13
Avatar de nramire1
nramire1 nramire1 está desconectado
Moderator
 
Fecha de Ingreso: diciembre-2008
Ubicación: Argentina
País:
Mensajes: 247
Agradecimientos: 7
Le agradecieron 62 veces
Poder de Credibilidad: 256
nramire1 es un nombre conocido por todosnramire1 es un nombre conocido por todosnramire1 es un nombre conocido por todosnramire1 es un nombre conocido por todosnramire1 es un nombre conocido por todosnramire1 es un nombre conocido por todos
Predeterminado

Revisa las coordenadas en donde inserta los JRadioButton. Porque están quedando debajo de un JTextField
El panel agregalo al JFrame al final
Código:
import javax.swing.ButtonGroup;
import javax.swing.JCheckBox;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JTextField;

public class Cliente extends javax.swing.JFrame {

    JPanel panel = new JPanel();
    JLabel vetiquetas[]= new JLabel[4];
    JTextField vcuadros[]= new JTextField[3];
    JRadioButton vopcion[]= new JRadioButton[2];
    JCheckBox check;
    ButtonGroup grupo = new ButtonGroup();

    public Cliente() {
//        initComponents();
        CreacionVentana();
    }
    public void CreacionVentana(){
        //Caracteristicas de la ventana
        this.setTitle("Registro Cliente");
        this.setSize(350,200);
        this.setDefaultCloseOperation(this.EXIT_ON_CLOSE);

        String vtextos[]={"Nombre:","Direccion:","Telefono:","Estado Civil:"};
        int i;
        for(i=0;i<vetiquetas.length;i++){
            vetiquetas[i]=new JLabel();
            vetiquetas[i].setText(vtextos[i]);
            vetiquetas[i].setBounds(10,10+30*i,100,20);
            this.getContentPane().add(vetiquetas[i]);
        }
        int y;
        for(y=0;y<vcuadros.length;y++){
            vcuadros[y]=new JTextField();
            vcuadros[y].setBounds(80, 10+30*y, 200, 20);
            this.getContentPane().add(vcuadros[y]);
        }
        String vopciones[]={"Soltero","Casado"};
        int z;
        for (z=0;z<vopcion.length;z++){
            vopcion[z]=new JRadioButton();
            vopcion[z].setText(vopciones[z]);
            vopcion[z].setBounds(90+80*z,10+30*y,80,20);
            this.getContentPane().add(vopcion[z]);
        }
        grupo.add(vopcion[0]);
        grupo.add(vopcion[1]);
        panel.add(vopcion[0]);
        panel.add(vopcion[1]);

        check=new JCheckBox();
        check.setText("Con hijos");
        check.setBounds(10,10+30*i,200,20);
        this.getContentPane().add(check);
        this.getContentPane().add(panel);

    }

    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new Cliente().setVisible(true);
            }
        });
    }
}
__________________
nramire1
www.nramire1.unlugar.com

Si pedís código, entrega el código.
Responder Citando
  #3  
Antiguo 30-jul-2010, 23:59
Avatar de slash365
slash365 slash365 está desconectado
Principiante
 
Fecha de Ingreso: julio-2010
País:
Mensajes: 2
Agradecimientos: 0
Le agradecieron 0 veces
Poder de Credibilidad: 0
slash365 no se puede calificar en este momento
Predeterminado

Cita:
Iniciado por nramire1 Ver Mensaje
Revisa las coordenadas en donde inserta los JRadioButton. Porque están quedando debajo de un JTextField
El panel agregalo al JFrame al final
Código:
import javax.swing.ButtonGroup;
import javax.swing.JCheckBox;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JTextField;

public class Cliente extends javax.swing.JFrame {

    JPanel panel = new JPanel();
    JLabel vetiquetas[]= new JLabel[4];
    JTextField vcuadros[]= new JTextField[3];
    JRadioButton vopcion[]= new JRadioButton[2];
    JCheckBox check;
    ButtonGroup grupo = new ButtonGroup();

    public Cliente() {
//        initComponents();
        CreacionVentana();
    }
    public void CreacionVentana(){
        //Caracteristicas de la ventana
        this.setTitle("Registro Cliente");
        this.setSize(350,200);
        this.setDefaultCloseOperation(this.EXIT_ON_CLOSE);

        String vtextos[]={"Nombre:","Direccion:","Telefono:","Estado Civil:"};
        int i;
        for(i=0;i<vetiquetas.length;i++){
            vetiquetas[i]=new JLabel();
            vetiquetas[i].setText(vtextos[i]);
            vetiquetas[i].setBounds(10,10+30*i,100,20);
            this.getContentPane().add(vetiquetas[i]);
        }
        int y;
        for(y=0;y<vcuadros.length;y++){
            vcuadros[y]=new JTextField();
            vcuadros[y].setBounds(80, 10+30*y, 200, 20);
            this.getContentPane().add(vcuadros[y]);
        }
        String vopciones[]={"Soltero","Casado"};
        int z;
        for (z=0;z<vopcion.length;z++){
            vopcion[z]=new JRadioButton();
            vopcion[z].setText(vopciones[z]);
            vopcion[z].setBounds(90+80*z,10+30*y,80,20);
            this.getContentPane().add(vopcion[z]);
        }
        grupo.add(vopcion[0]);
        grupo.add(vopcion[1]);
        panel.add(vopcion[0]);
        panel.add(vopcion[1]);

        check=new JCheckBox();
        check.setText("Con hijos");
        check.setBounds(10,10+30*i,200,20);
        this.getContentPane().add(check);
        this.getContentPane().add(panel);

    }

    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new Cliente().setVisible(true);
            }
        });
    }
}
Hola, En el primer codigo si aparecen las opciones al lado del Estado civil, pero si agrego el Jpanel, se sobrepone.Asi lo cambie de lugar;En cambio en el codigo q me das, las opciones aparecen en un lugar q no deberia aparecer segun (.setBounds(90+80*z,10+30*y,80,20).Parece q el JPanel aparece por defecto en medio de la primera caja de texto.
Como le asigno la posicion a ese JPanel?
Gracias.
Responder Citando
Respuesta

Marcadores

Herramientas Buscar en Tema
Buscar en Tema:

Búsqueda Avanzada
Desplegado

Normas de Publicación
No puedes crear nuevos temas
No puedes responder temas
No puedes subir archivos adjuntos
No puedes editar tus mensajes

Los Códigos BB están Activado
Las Caritas están Activado
[IMG] está Activado
El Código HTML está Desactivado
Ir al Foro

Temas Similares
Tema Autor Foro Respuestas Último mensaje
Arreglo de Componentes. Bof Java Básico 6 22-jun-2010 16:47
problemas al agregar un jtable en un jpanel juan0055 AWT-SWING 4 09-jun-2010 13:24
Agregar componentes dinamicamente en JPanel - No Refresca cristiancrm AWT-SWING 3 07-dic-2009 05:31
Agregar un JPanel nuevo a un JFrame juancarlos16 AWT-SWING 1 24-oct-2008 16:19
Componentes GUI Nano Java Básico 2 18-feb-2008 13:24

 

La franja horaria es GMT. Ahora son las 05:35.
"Simplicity" made by SimpleGfxDesigns
Powered by vBulletin® Version 3.7.4
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.