• Sábado 11 de Mayo de 2024, 09:39

Autor Tema:  Introducir Jlist  (Leído 1778 veces)

hitman47

  • Miembro activo
  • **
  • Mensajes: 81
  • Nacionalidad: pa
    • Ver Perfil
    • http://softwareistmenio.blogspot.com
Introducir Jlist
« en: Sábado 2 de Octubre de 2004, 15:22 »
0
Hola  me pueden ayudar y decirme que sucede con este codigo que no introduce correctamente la JList en el JFrame
import java.awt.*;
//import java.awt.event.*;
import javax.swing.*;

class Proy extends JFrame
{
   String label [] = {"Cranberry", "Orange", //elementos de la lista
    "Banana", "Kiwi", "Blueberry",
    "Pomegranate", "Apple", "Pear",
    "Watermelon", "Raspberry", "Snozberry"};
JLabel eti2;
JTextField texto;
JLabel eti1;
JList list;
//JButton b1;


Proy(){ //constructor
list = new JList(label);
list.setVisibleRowCount(5);//#d objetos visibles en la lista
JScrollPane scroll = new JScrollPane(list);//barra de scroll para la lista
eti2 = new JLabel("LISTADO DE CANCIONES POR COMPOSITOR / INTERPRETE");
texto = new JTextField(10);
eti1 = new JLabel("Compositor/Interprete:");

this.getContentPane().setBackground(new Color(167,180,205));

this.getContentPane().add(eti1);
this.getContentPane().add(texto);
this.getContentPane().add(eti2);
this.getContentPane().add(scroll);
scroll.setBounds(270,170,30,70);
texto.setBounds(170,50,160,30);
eti1.setBounds(20,50,150,30);
eti2.setBounds(120,50,160,30);

} //fin del constructor   
   

public static void main(String args[]){

Proy obj = new Proy();

obj.setTitle("Listado de canciones por Compositor/ Interprete");
obj.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
obj.setBounds(210,100,450,400);
obj.setVisible(true);   
   
}
   
}

SALU2 :(

hitman47

  • Miembro activo
  • **
  • Mensajes: 81
  • Nacionalidad: pa
    • Ver Perfil
    • http://softwareistmenio.blogspot.com
Re: Introducir Jlist
« Respuesta #1 en: Martes 5 de Octubre de 2004, 05:40 »
0
ya encontre la solucion solo tengo que insertar la intruccion
this.getContentPane().setLayout(null);
Código: Text
  1. Proy(){ //constructor
  2. list = new JList(label);
  3. list.setVisibleRowCount(5);//#d objetos visibles en la lista
  4. JScrollPane scroll = new JScrollPane(list);//barra de scroll para la lista
  5. eti2 = new JLabel("LISTADO DE CANCIONES POR COMPOSITOR / INTERPRETE");
  6. texto = new JTextField(10);
  7. eti1 = new JLabel("Compositor/Interprete:");
  8.  
  9. this.getContentPane().setLayout(null);
  10. this.getContentPane().setBackground(new Color(167,180,205));
  11.  
  12. this.getContentPane().add(eti1);
  13. this.getContentPane().add(texto);
  14. this.getContentPane().add(eti2);
  15. this.getContentPane().add(scroll);
  16. scroll.setBounds(270,170,30,70);
  17. texto.setBounds(170,15,160,30);
  18. eti1.setBounds(20,15,150,30);
  19. eti2.setBounds(120,50,160,30);
  20.  
  21. } //fin del constructor
  22.  
SALU2  :kicking: