Article View: es.comp.lenguajes.java
Article #186Re: Java Jtable Vector
From: Ricardo Palomares Martinez
Date: Sun, 18 Nov 2007 19:36
Date: Sun, 18 Nov 2007 19:36
71 lines
3378 bytes
3378 bytes
AlejandroArias escribió:
> Saludos tengo un vector asi:
>
> Vector ListadoCD = new Vector();
>
> ListadoCD.addElement(new CD("R1", "50 Cent", "Rap", "20000"));
> ListadoCD.addElement(new CD("P2", "Ricardo Arjona", "Pop",
> "35000"));
> ListadoCD.addElement(new CD("D3", "Antoine Clamaran","Dance",
> "30000"));
> ListadoCD.addElement(new CD("S5", "Victor Manuelle","Salsa",
> "23000"));
>
>
> ESto es loq sifnifica los datos
>
> lblCodigoCD = new JLabel("Codigo");
> lblArtista = new JLabel("Artista");
> lblGenero = new JLabel("Genero");
> lblPrecio = new JLabel("Precio");
>
>
> NEcesito mostrarlo en un JTable
>
> DefaultTableModel modelo = new DefaultTableModel();
>
> JTable Tabla = new JTable(modelo);
> BorderLayout borderLayout1 = new BorderLayout();
>
> final JTable table = new JTable(ListadoCD, titulos);
> table.setPreferredScrollableViewportSize(new
> Dimension(500, 70));
>
> Pero me dice que el tipo de ListadoCD no es strig, que debo hacer para
> solucionar esto?
Diría que leer la documentación puede ser un primer paso:
http://java.sun.com/javase/6/docs/api/javax/swing/JTable.html
http://java.sun.com/docs/books/tutorial/uiswing/index.html
Estás creando un Vector, luego un TableModel, luego un JTable (Tabla),
y luego otro JTable que usa ListadoCD como datos de un
DefaultTableModel. Los títulos de las columnas nos los muestras como
JLabels, y no veo por ningún lado qué es "titulos".
No nos enseñas todo el código relevante, pero si tiene la misma
organización que el que has puesto, es que puede haber de todo ahí. Si
quieres crear una tabla con una serie de datos fijos como los que
propones, debería bastar con algo así:
String[] columnNames = {"Código", "Artista", "Género", "Precio"};
Object[][] data = {
{"R1", "50 Cent", "Rap", new Integer(20000)},
{"P2", "Ricardo Arjona", "Pop", new Integer(35000),
(...)
};
JTable table = new JTable(data, columnNames);
Vector es una clase "thread-safe", lo que la hace ser bastante lenta.
Deberías acostumbrarte a usarla sólo cuando sea imprescindible.
Saludos.
--
If it's true that we are here to help others,
then what exactly are the OTHERS here for?
Technical Details
Message-ID:
<mrg615-fc7.ln1@Father.family>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!feeder1-2.proxad.net!proxad.net!feeder1-1.proxad.net!club-internet.fr!feedme-small.clubint.net!aioe.org!newsReferences:
<053d3b49-8628-419d-97cf-805e4a6c7f54@b36g2000hsa.googlegroups.com>Show Full Headers
Complete Article Headers
X-Google-Thread: 1116f3,2e0e81303808177b X-Google-Attributes: gid1116f3,public,usenet X-Google-Language: SPANISH,ASCII Path: arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!feeder1-2.proxad.net!proxad.net!feeder1-1.proxad.net!club-internet.fr!feedme-small.clubint.net!aioe.org!news From: Ricardo Palomares Martinez <rpm.PUBLI@iespana.es> Newsgroups: es.comp.lenguajes.java Subject: Re: Java Jtable Vector Date: Sun, 18 Nov 2007 20:36:54 +0100 Organization: Hogar, dulce hogar Lines: 71 Message-ID: <mrg615-fc7.ln1@Father.family> References: <053d3b49-8628-419d-97cf-805e4a6c7f54@b36g2000hsa.googlegroups.com> NNTP-Posting-Host: MEPavIo3sFitiHNect+qlA.user.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Complaints-To: abuse@aioe.org User-Agent: Mozilla/5.0 (X11; U; Linux i686; es-ES; rv:1.8.1.8) Gecko/20071009 SeaMonkey/1.1.5 Mnenhy/0.7.5.666