|
 |

28-jul-2010, 17:18
|
 |
Principiante
|
|
Fecha de Ingreso: julio-2010
País:
Mensajes: 2
Agradecimientos: 0
Le agradecieron 0 veces
Poder de Credibilidad: 0
|
|
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.
|
| Entre a los Links relacionados |
|
|

29-jul-2010, 15:13
|
 |
Moderator
|
|
Fecha de Ingreso: diciembre-2008
Ubicación: Argentina
País:
Mensajes: 247
Agradecimientos: 7
Le agradecieron 62 veces
Poder de Credibilidad: 256
|
|
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);
}
});
}
}
|

30-jul-2010, 23:59
|
 |
Principiante
|
|
Fecha de Ingreso: julio-2010
País:
Mensajes: 2
Agradecimientos: 0
Le agradecieron 0 veces
Poder de Credibilidad: 0
|
|
Cita:
Iniciado por nramire1
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.
|
| Herramientas |
Buscar en Tema |
|
|
|
| Desplegado |
Mode Lineal
|
Normas de Publicación
|
No puedes crear nuevos temas
No puedes responder temas
No puedes subir archivos adjuntos
No puedes editar tus mensajes
El Código HTML está Desactivado
|
|
|
|
 |
|
 |
La franja horaria es GMT. Ahora son las 05:35.
|
 |