<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:blogger='http://schemas.google.com/blogger/2008' xmlns:georss='http://www.georss.org/georss' xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-2058716862278766723</id><updated>2024-09-05T06:57:47.685-07:00</updated><title type='text'>blogeando lo poco que se</title><subtitle type='html'>blog de java, netbeans y uno que otro tema&#xa;para compartir lo poco que se</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://faq-netbeans.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2058716862278766723/posts/default?redirect=false'/><link rel='alternate' type='text/html' href='http://faq-netbeans.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>luismi_va</name><uri>http://www.blogger.com/profile/04947152389082524194</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>2</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-2058716862278766723.post-7365128427546324333</id><published>2013-01-07T20:57:00.002-08:00</published><updated>2013-01-07T20:57:28.351-08:00</updated><title type='text'>Graficos en Java, la técnica DobleBuffering</title><content type='html'>&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;font-family: Verdana,sans-serif;&quot;&gt;Increíble casi hace 2 años de la ultima entrada... de hecho probablemente cuando la publique ya serán 2 años... pero bueno... espero perdonen mi lentitud, cada día uno sabe mas cosas... y no las comparte que egoísta &quot;la gente&quot; :P jajaja.&lt;br /&gt;
&lt;br /&gt;
Bueno esta vez explicare algo relativamente sencillo, como utilizar doble buffer en java, se que existen cientos de lugares, donde explican esto, pero a mi parecer lo explican de una forma muy compleja, cuando en realidad es algo muy sencillo y util en la mayoría de los casos.&lt;br /&gt;
&lt;br /&gt;
Antes de pasar al código... deberías tener un conocimiento básico de como utilizar gráficos en java... es decir saber dibujar una figura, una cadena, o una imagen algo asi... el problema que trato de exponer es cuando intentas hacer que&amp;nbsp; lo que sea que dibujas &quot;se mueva&quot;, para hacer que una imagen &quot;se mueva&quot; a través de la pantalla se requiere reemplazar la figura con otra parecida en una ubicación diferente en la pantalla, pero al intentarlo solo sabiendo utilizar el método paint() de la clase Canvas te das cuenta que &quot;parpadea&quot;, &quot;flashea&quot;.&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;font-family: Verdana,sans-serif;&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;font-family: Verdana,sans-serif;&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;font-family: Verdana,sans-serif;&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;font-family: Verdana,sans-serif;&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;font-family: Verdana,sans-serif;&quot;&gt;Ej. supongamos que queremos que un personaje camine, tenemos imágenes de un sprite sheet... programamos y llegamos al punto en el que tenemos una imagen algo asi:&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;font-family: Verdana,sans-serif;&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;font-family: Verdana,sans-serif;&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;font-family: Verdana,sans-serif;&quot;&gt;
&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjr8ew-uUlOAnmcrewW-hcvQSxsqO5WSDPZ-xm5sWaFpU8lxQ-sc26MFF1kobVdmbIuEaqxwxwB11ypgrKjDNn2ZUICc8GdnPN21t1KM0YaVIRJGNv2QPidBwMjvhA3JVgSvj4TnIiQ0dOT/s1600/zero.gif&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjr8ew-uUlOAnmcrewW-hcvQSxsqO5WSDPZ-xm5sWaFpU8lxQ-sc26MFF1kobVdmbIuEaqxwxwB11ypgrKjDNn2ZUICc8GdnPN21t1KM0YaVIRJGNv2QPidBwMjvhA3JVgSvj4TnIiQ0dOT/s1600/zero.gif&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;span style=&quot;font-family: Verdana,sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Verdana,sans-serif;&quot;&gt;Esto pasa porque la clase Canvas cuenta con un método llamado update, el cual borra completamente la pantalla en ciertas ocasiones, y es el culpable de dicho parpadeo... en realidad si tu metodo paint() borra la imagen anterior, no es necesario que update borre la imagen completa, este detalle se corrige sobreescribiendo update con tu codigo de paint() y haciendo que paint llame a update() asi:&lt;/span&gt;
&lt;/div&gt;
&lt;br /&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: Verdana,sans-serif;&quot;&gt;&amp;nbsp;   &lt;span style=&quot;color: #666666;&quot;&gt;...&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: Verdana,sans-serif;&quot;&gt;    @Override
    &lt;span style=&quot;color: blue;&quot;&gt;public void&lt;/span&gt; &lt;b&gt;update&lt;/b&gt;(Graphics g){
        &lt;span style=&quot;color: #3d85c6;&quot;&gt;//el codigo que tenias en paint tal cual&lt;/span&gt;
    }
    
    @Override
    &lt;span style=&quot;color: blue;&quot;&gt;public void &lt;span style=&quot;color: black;&quot;&gt;&lt;b&gt;paint&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;(Graphics g){
        update(g);&lt;span style=&quot;background-color: #3d85c6;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #3d85c6;&quot;&gt;//se llama al metodo update&lt;/span&gt;
    }&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: Verdana,sans-serif;&quot;&gt;    &lt;span style=&quot;color: #666666;&quot;&gt;...&lt;/span&gt; &lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: Verdana,sans-serif;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: Verdana,sans-serif;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/pre&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiK67MxjTrHnhPZp1DY0UIrdqyaOYgZN7vIPz167WV5BKgw6yjPSJbrogotmc5RDOFNj6LAzEZ2Ssx1cImL8AOhnK54IDcltcKkdH1ICMdDaJSWPhi_gLKzcO9nThc-KDNf18XUnJETUoCn/s1600/zero2.gif&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiK67MxjTrHnhPZp1DY0UIrdqyaOYgZN7vIPz167WV5BKgw6yjPSJbrogotmc5RDOFNj6LAzEZ2Ssx1cImL8AOhnK54IDcltcKkdH1ICMdDaJSWPhi_gLKzcO9nThc-KDNf18XUnJETUoCn/s1600/zero2.gif&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;font-family: Verdana,sans-serif;&quot;&gt;Pero aun así obtendríamos una imagen que sigue&amp;nbsp; parpadeando aparentemente menos, pero continua...esto es porque nosotros mismos borramos la imagen antes de dibujar la siguiente, o al menos eso deberíamos hacer..., por lo tanto en cierto momento la pantalla esta vacía... se utiliza la técnica DobleBuffering la cual consiste en solo dibujar imagenes completas en pantalla, esto es mas fácil de explicar con imagenes, la imagen de abajo muestra como funcionaria el código sin usar DobleBuffering:&lt;/span&gt;&lt;/div&gt;
&lt;span style=&quot;font-family: Verdana,sans-serif;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiD7zjMRf3BjV50AnNhartcw0D7VphI2ibvVTq5666ffTCxGsfMX59xAbG5RNsPrw9YOV3hw_vZnVg69qUB0ybIqm-SBjRonT7sx2V-DgtVivHl8PWBW37CWdNIoeQX5S6XRUA-gYzAEvKj/s1600/sinDB.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;114&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiD7zjMRf3BjV50AnNhartcw0D7VphI2ibvVTq5666ffTCxGsfMX59xAbG5RNsPrw9YOV3hw_vZnVg69qUB0ybIqm-SBjRonT7sx2V-DgtVivHl8PWBW37CWdNIoeQX5S6XRUA-gYzAEvKj/s320/sinDB.png&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjKxTiZ_StyFjCHM2uNSKiiQJi0VniYtqwGqCwqTnv-FHg8scZOKSXIBHLNKdH4GjDJTBObpTMTi28HMQdZkhuwCeVE4lHxeMWxP78HUBfKiN6Z2QzI37-MUMIgzQWBJLvXRZxnpc4UiH6J/s1600/DB.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;/a&gt;&lt;/div&gt;
&lt;span style=&quot;font-family: Verdana,sans-serif;&quot;&gt;Doble buffering consiste realizar los cálculos y dibujar las figuras en memoria antes de mostrarlos al usuario la siguiente imagen muestra de forma mas gráfica doble buffering&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjKxTiZ_StyFjCHM2uNSKiiQJi0VniYtqwGqCwqTnv-FHg8scZOKSXIBHLNKdH4GjDJTBObpTMTi28HMQdZkhuwCeVE4lHxeMWxP78HUBfKiN6Z2QzI37-MUMIgzQWBJLvXRZxnpc4UiH6J/s1600/DB.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;144&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjKxTiZ_StyFjCHM2uNSKiiQJi0VniYtqwGqCwqTnv-FHg8scZOKSXIBHLNKdH4GjDJTBObpTMTi28HMQdZkhuwCeVE4lHxeMWxP78HUBfKiN6Z2QzI37-MUMIgzQWBJLvXRZxnpc4UiH6J/s320/DB.png&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;font-family: Verdana,sans-serif;&quot;&gt;Utilizar esta técnica es relativamente sencillo solo debemos agregar dos nuevos atributos en nuestra clase Canvas una imagen y un objeto Graphics, y en el constructor inicializamos estos atributos creando un nuevo objeto BufferedImage y obteniendo su objeto Graphics con el método getGraphics() ahora en nuestro método update en lugar de utilizar el parámetro Graphics utilizaremos el objeto Graphics de nuestra imagen que esta en memoria y al final solo dibujaremos la imagen de la memoria la cual ya fue completamente renderizada, podemos verlo mejor en el siguiente fragmento de código&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;pre&gt;&lt;span style=&quot;color: blue;&quot;&gt;public class&lt;/span&gt; MiCanvas &lt;span style=&quot;color: blue;&quot;&gt;extends&lt;/span&gt; Canvas{
    &lt;span style=&quot;color: blue;&quot;&gt;public static final int&lt;/span&gt; &lt;span style=&quot;color: #6aa84f;&quot;&gt;_WIDTH&lt;/span&gt;;
    &lt;span style=&quot;color: blue;&quot;&gt;public static final int&lt;/span&gt; &lt;span style=&quot;color: #6aa84f;&quot;&gt;_HEIGHT&lt;/span&gt;;
    &lt;span style=&quot;color: blue;&quot;&gt;private&lt;/span&gt; BufferedImage &lt;span style=&quot;color: #e69138;&quot;&gt;imagenBuffer&lt;/span&gt;;
    &lt;span style=&quot;color: blue;&quot;&gt;private&lt;/span&gt; Graphics &lt;span style=&quot;color: #e69138;&quot;&gt;g_imagenBuffer&lt;/span&gt;;&lt;/pre&gt;
&lt;pre&gt;&amp;nbsp;&lt;/pre&gt;
&lt;pre&gt;   &amp;nbsp;&lt;span style=&quot;color: blue;&quot;&gt;public&lt;/span&gt; MiCanvas(){
        &lt;span style=&quot;color: blue;&quot;&gt;this&lt;/span&gt;.setSize(&lt;span style=&quot;color: #6aa84f;&quot;&gt;_WIDTH&lt;/span&gt;, &lt;span style=&quot;color: #6aa84f;&quot;&gt;_HEIGHT&lt;/span&gt;);
        &lt;span style=&quot;color: #6fa8dc;&quot;&gt;//creamos la imagen en memoria&lt;/span&gt;
        &lt;span style=&quot;color: #e69138;&quot;&gt;imagenBuffer&lt;/span&gt; = &lt;span style=&quot;color: blue;&quot;&gt;new&lt;/span&gt; BufferedImage(&lt;span style=&quot;color: #6aa84f;&quot;&gt;_WIDTH&lt;/span&gt;,&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;color: #6aa84f;&quot;&gt;                          _HEIGHT&lt;/span&gt;,&amp;nbsp;&lt;/pre&gt;
&lt;pre&gt;                          BufferedImage.&lt;span style=&quot;color: #6aa84f;&quot;&gt;TYPE_INT_RGB&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;color: #6aa84f;&quot;&gt;                      &lt;/span&gt;);
        &lt;span style=&quot;color: #3d85c6;&quot;&gt;//obtenemos los graficos&lt;/span&gt;
        &lt;span style=&quot;color: #e69138;&quot;&gt;g_imagenBuffer&lt;/span&gt; = &lt;span style=&quot;color: #e69138;&quot;&gt;imagenBuffer&lt;/span&gt;.getGraphics();
    }
    
    @Override
    &lt;span style=&quot;color: blue;&quot;&gt;public void&lt;/span&gt; update(Graphics g){
       &lt;span style=&quot;color: #3d85c6;&quot;&gt;//realizamos nuestros calculos&amp;nbsp;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;color: #3d85c6;&quot;&gt;       //pero ahora utilizando &lt;b&gt;g_imagenBuffer&lt;/b&gt; en lugar de &lt;b&gt;g&lt;/b&gt;
       //y por ultimo imprimimos la imagen que tenemos en  memoria&lt;/span&gt;
       g.drawImage( &lt;span style=&quot;color: #e69138;&quot;&gt;imagenBuffer&lt;/span&gt;, 0, 0, &lt;span style=&quot;color: blue;&quot;&gt;this&lt;/span&gt; );
    }&lt;/pre&gt;
&lt;pre&gt;    &lt;span style=&quot;color: #666666;&quot;&gt;...&lt;/span&gt; &lt;/pre&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Después de haber realizado los cambios, nuestro personaje caminará mas fluido como se muestra en esta imagen:&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiCoMtEpwbhiflmN_vRo7himic9_tT9BzcM5hHemIrLG5X3mJEttB4oMU3fZf37DhduZPJJEqh_RTQ930gr_caeyLXMByFwpjUQrPzw0IgFf2VJyivKvGAe3WvhGDBWEb0foLOX-ggRhw3f/s1600/zero+doblebuffer.gif&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiCoMtEpwbhiflmN_vRo7himic9_tT9BzcM5hHemIrLG5X3mJEttB4oMU3fZf37DhduZPJJEqh_RTQ930gr_caeyLXMByFwpjUQrPzw0IgFf2VJyivKvGAe3WvhGDBWEb0foLOX-ggRhw3f/s1600/zero+doblebuffer.gif&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Pero no le crean a los las imágenes gif, pueden hacer la prueba ustedes mismos yo igual dejo el código del Megaman donde se puede ver el uso del DobleBuffering lo cual es una técnica sencilla, pero muy útil.&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
liga para descargar el código fuente del proyecto de NetBeans Megaman:&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;a href=&quot;https://www.dropbox.com/s/bhx2dbhtgnr27zd/Megaman.zip&quot; target=&quot;_blank&quot;&gt;Proyecto de NetBeans &quot;Megaman&quot;&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana,sans-serif;&quot;&gt;Si llegaste hasta este párrafo... ¡¡¡Muchas gracias por leer mi blog!!! un entrada cada 2 años... difícil tener fans jajaja ;) hasta la próxima esperemos que sea menos de 2 años.&lt;/span&gt; &lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://faq-netbeans.blogspot.com/feeds/7365128427546324333/comments/default' title='Comentarios de la entrada'/><link rel='replies' type='text/html' href='http://faq-netbeans.blogspot.com/2013/01/graficos-en-java-la-tecnica.html#comment-form' title='3 Comentarios'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2058716862278766723/posts/default/7365128427546324333'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2058716862278766723/posts/default/7365128427546324333'/><link rel='alternate' type='text/html' href='http://faq-netbeans.blogspot.com/2013/01/graficos-en-java-la-tecnica.html' title='Graficos en Java, la técnica DobleBuffering'/><author><name>luismi_va</name><uri>http://www.blogger.com/profile/04947152389082524194</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjr8ew-uUlOAnmcrewW-hcvQSxsqO5WSDPZ-xm5sWaFpU8lxQ-sc26MFF1kobVdmbIuEaqxwxwB11ypgrKjDNn2ZUICc8GdnPN21t1KM0YaVIRJGNv2QPidBwMjvhA3JVgSvj4TnIiQ0dOT/s72-c/zero.gif" height="72" width="72"/><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2058716862278766723.post-565358808368664460</id><published>2011-01-11T22:13:00.000-08:00</published><updated>2011-11-22T20:54:44.440-08:00</updated><title type='text'>Tablas en netbeans</title><content type='html'>muchas veces me han preguntado, oye como se usan las tablas en netbeans? o como puedo hacer&amp;nbsp;dinámica&amp;nbsp;una tabla en java?, y la mas frecuente como puedo hacer&amp;nbsp;dinámica&amp;nbsp;una tabla con netbeans? la cual es la misma que la anterior, por lo que&amp;nbsp;decidí&amp;nbsp;escribir cada paso de lo que yo normalmente hago cuando manejo tablas, no se si sea lo mas correcto, pero a mi me funciona:&lt;br /&gt;
&lt;br /&gt;
Aquí&amp;nbsp;supondré&amp;nbsp;que sabemos usar netbeans hasta el punto en el que se inserta una tabla, es decir cuando podemos ver algo como esto:&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjNKCyHqeRFXP30BejWJUJcbzT-R2MyBv9um7c4rlUdwzcmitrBMGICM1DOwnQp_b8MRULb50PmmYqQlzcrFru6nZPscvde0Jtgk2CAbOsDYl7Pl-YzOpQUX39CFdIyC21Wp3QP2jMWA_lj/s1600/EjemplosBlog0.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;223&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjNKCyHqeRFXP30BejWJUJcbzT-R2MyBv9um7c4rlUdwzcmitrBMGICM1DOwnQp_b8MRULb50PmmYqQlzcrFru6nZPscvde0Jtgk2CAbOsDYl7Pl-YzOpQUX39CFdIyC21Wp3QP2jMWA_lj/s400/EjemplosBlog0.png&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
ya teniendo la tabla creada se pueden modificar sus propiedades de forma&amp;nbsp;gráfica&amp;nbsp;dando click-derecho sobre la tabla que creamos&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgiFPW0ICgYqTfA-hTZdzppK14ASJoryhW0w4BCGyzIWUSaQexr7g1tfwZy0qM8pps1vmLRtTF5xzWYIVZPpFNBF8UYL1jo6_Ni6QYsa56x0gvXbKfjyDYYUf735OrI1O_V7y5PKqDrjhbE/s1600/Screenshot-EjemplosBlog+-+NetBeans+IDE+6.9.1-1.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;400&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgiFPW0ICgYqTfA-hTZdzppK14ASJoryhW0w4BCGyzIWUSaQexr7g1tfwZy0qM8pps1vmLRtTF5xzWYIVZPpFNBF8UYL1jo6_Ni6QYsa56x0gvXbKfjyDYYUf735OrI1O_V7y5PKqDrjhbE/s400/Screenshot-EjemplosBlog+-+NetBeans+IDE+6.9.1-1.png&quot; width=&quot;272&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
aparecerá&amp;nbsp;un cuadro de dialogo que describe las propiedades de la tabla, en la primera pestaña &quot;modelo de la tabla&quot; se indica de donde se&amp;nbsp;obtendrán&amp;nbsp;los datos de la tabla, la verdad, de esa pestaña no se casi nada si&amp;nbsp;embargo&amp;nbsp;si nos&amp;nbsp;pasamos&amp;nbsp;a la pestaña que dice Columnas 1&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjkRsLkEhN6oQqQfIao5WcITBmVoqHET-uXLtPumFcYhbl7oEqjqBGPcaLVOYykpbd3twDdC5s5p6TCJj1ASYesbgPhNV_g5ap90T1WOl3zrXeIH3a5exJQ7Kz_wwD3ki8T3zJ-u1xMJYmx/s1600/Screenshot-Customizer+Dialog-2.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;362&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjkRsLkEhN6oQqQfIao5WcITBmVoqHET-uXLtPumFcYhbl7oEqjqBGPcaLVOYykpbd3twDdC5s5p6TCJj1ASYesbgPhNV_g5ap90T1WOl3zrXeIH3a5exJQ7Kz_wwD3ki8T3zJ-u1xMJYmx/s400/Screenshot-Customizer+Dialog-2.png&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
podemos ver las propiedades de cada columna 2 en esta parte podemos cambiar el tipo de el valor que aceptara la tabla, si es editable o si se&amp;nbsp;puede cambiar&amp;nbsp;el tamaño de la celda y por supuesto el nombre de la columna y los&amp;nbsp;números&amp;nbsp;3,4,5,6 en la&amp;nbsp;selección&amp;nbsp;de modelo indican la forma en que se&amp;nbsp;podrán seleccionar&amp;nbsp;las celdas de la tabla; a&amp;nbsp;continuación&amp;nbsp;una&amp;nbsp;descripción&amp;nbsp;de lo que hacen:&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
3 solo permite la&amp;nbsp;selección&amp;nbsp;de filas&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
si se selecciona 4 solo se&amp;nbsp;podrá&amp;nbsp;seleccionar una sola celda&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
si se selecciona 5 se&amp;nbsp;podrá&amp;nbsp;seleccionar&amp;nbsp;múltiples&amp;nbsp;celdas, pero estas&amp;nbsp;deberán&amp;nbsp;ser vecinas&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
y por ultimo si se selecciona 6 se&amp;nbsp;podrá&amp;nbsp;seleccionar celdas sin importar que sean vecinas o no&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhAer6KEfwdg8_E127Q15-dLa2pNd-ybWcKKeVohAtt58hZt60r2H_RcNlnwBwI078wlMf6vXVe9GangkDOWAMqieSIdMk36c3zg4Le9OqiN24Dca0nHVoNXHRzBhRFU4DuzaGKlY_1h2UM/s1600/Screenshot-Customizer+Dialog.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;290&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhAer6KEfwdg8_E127Q15-dLa2pNd-ybWcKKeVohAtt58hZt60r2H_RcNlnwBwI078wlMf6vXVe9GangkDOWAMqieSIdMk36c3zg4Le9OqiN24Dca0nHVoNXHRzBhRFU4DuzaGKlY_1h2UM/s320/Screenshot-Customizer+Dialog.png&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
Los tipos que se pueden seleccionar en las tablas son los que se muestran en la imagen, lo cual puede ser&amp;nbsp;útil&amp;nbsp;para recabar datos con formato, en lo personal, no me gusta usar las jtables para recabar datos porque siempre se tiene un problema al insertar el ultimo dato, pero de igual forma al definir el tipo del objeto de una columna esta no aceptara que se inserte otro tipo de valor y en&amp;nbsp;adición, al seleccionar boolean el valor de las columnas cambiaran por &amp;nbsp;un checkbox donde la palomita significa true, y&amp;nbsp;vació&amp;nbsp;false&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi3DpuIxoY4Ubb-iiImwr9cP7MSZedPoxq_WlPpVTWFewXj_6DxRY9P4hUxxm3BVGSwIdYOC-8QdeVspUQjqBJZDy65uuWr5qZZgCLziv1eJhJm0Aj3WqajNakhMrqfV63fe5A3msUIDOrb/s1600/Screenshot-Customizer+Dialog-3.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;290&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi3DpuIxoY4Ubb-iiImwr9cP7MSZedPoxq_WlPpVTWFewXj_6DxRY9P4hUxxm3BVGSwIdYOC-8QdeVspUQjqBJZDy65uuWr5qZZgCLziv1eJhJm0Aj3WqajNakhMrqfV63fe5A3msUIDOrb/s320/Screenshot-Customizer+Dialog-3.png&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
Después&amp;nbsp;de cambiarle el formato a la tabla todo lo que quieras, podemos seguir con lo&amp;nbsp;dinámico, ahhh la pestaña de filas o rows solo permite agregar o quitar renglones en la tabla, pero bueno eso no nos sirve si lo que queremos es ponerlos dinamicamente.&amp;nbsp;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
Esto de formatear la tabla&amp;nbsp;servirá&amp;nbsp;ahora tenemos una tabla&amp;nbsp;que&amp;nbsp;solo acepta ciertos tipos de datos, con todos los renglones en blanco.&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
estas tablas, sin tener que ver con netbeans se manejan de forma diferente de la que muchos pensamos, la jTable es mas bien una&amp;nbsp;versión&amp;nbsp;gráfica, y sus datos provienen de un TableModel y ese es el que se necesita saber utilizar bueno, en si el TableModel no, sino un hijo de este, el DefaultTableModel, el cual permite manipularlo&amp;nbsp;fácilmente. solo necesitamos pues sacarlo de&amp;nbsp;ahí, ya que si revisas el&amp;nbsp;código&amp;nbsp;que genero el netbeans en la&amp;nbsp;función&amp;nbsp;de initComponents dice algo como&amp;nbsp;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: blue;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: blue;&quot;&gt;new&lt;/span&gt; jtable(&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: blue;&quot;&gt;new&lt;/span&gt; DefaultTableModel{&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: red;&quot;&gt;cosas raras de netbeans&lt;/span&gt;});&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: inherit;&quot;&gt;en las cosas raras de &lt;/span&gt;netbeans&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: inherit;&quot;&gt;&amp;nbsp;se desarrollan todas las&amp;nbsp;&lt;/span&gt;características&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: inherit;&quot;&gt;&amp;nbsp;que seleccionamos&amp;nbsp;&lt;/span&gt;gráficamente&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: inherit;&quot;&gt;&amp;nbsp;para aplicar a la tabla, entonces,&amp;nbsp;&lt;/span&gt;después&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: inherit;&quot;&gt;&amp;nbsp;de &lt;/span&gt;initComponets&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: inherit;&quot;&gt; sacamos el objeto del modelo de la tabla, lo &lt;/span&gt;casteamos&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: inherit;&quot;&gt; y lo guardamos en un atributo de nuestra clase.&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: inherit;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: blue;&quot;&gt;private&lt;/span&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;javax.swing.table.DefaultTableModel &lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #38761d;&quot;&gt;modelo&lt;/span&gt;;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #999999; font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;//atributo de nuestra clase&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: blue;&quot;&gt;public&lt;/span&gt; Inicio() {&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #999999;&quot;&gt;//este es el constructor de la tabla&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;initComponents();&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #38761d;&quot;&gt;modelo&lt;/span&gt; = (javax.swing.table.DefaultTableModel)&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #38761d;&quot;&gt;tabla&lt;/span&gt;.getModel();&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: white;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #999999;&quot;&gt;//con esta linea obtenemos el modelo&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: white;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #999999;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: black;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #38761d;&quot;&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;tabla&lt;/span&gt;.setModel(&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #38761d;&quot;&gt;modelo&lt;/span&gt;);&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: white; color: #999999; font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;//con esta instruccion se pueden cambiar las caracteristicas de la tabla por otro modelo&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;}&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: inherit;&quot;&gt;y con el modelo guardado podemos realizar varias acciones como agregar un renglón, borrar un renglón, agregar datos,&amp;nbsp;&lt;/span&gt;modificarlos&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: inherit;&quot;&gt;, y obtener los valores de la tabla.&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: inherit;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #666666; font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;//borrar renglón seleccionado&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: blue;&quot;&gt;try&lt;/span&gt;{&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #38761d;&quot;&gt;modelo&lt;/span&gt;.removeRow(&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #38761d;&quot;&gt;tabla&lt;/span&gt;.getSelectedRow());&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;}&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: blue;&quot;&gt;catch&lt;/span&gt;(Exception e){&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;javax.swing.JOptionPane.showMessageDialog(&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: blue;&quot;&gt;this&lt;/span&gt;, &lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #b45f06;&quot;&gt;&quot;Seleccione almenos&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #b45f06;&quot;&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;una celda&quot;&lt;/span&gt;,&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #b45f06;&quot;&gt;&quot;Error&quot;&lt;/span&gt;,javax.swing.JOptionPane.&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #38761d;&quot;&gt;ERROR_MESSAGE&lt;/span&gt;);&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;}&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #666666; font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;//insertar renglón con datos&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #38761d;&quot;&gt;modelo&lt;/span&gt;.addRow(&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: blue;&quot;&gt;new&lt;/span&gt; Object[]{23,&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #b45f06;&quot;&gt;&quot;Hola&quot;&lt;/span&gt;,23.5,&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: blue;&quot;&gt;true&lt;/span&gt;});&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #666666;&quot;&gt;//Los datos del nuevo&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #666666;&quot;&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;renglon de la tabla, se puede insertar un renglon vacio si en lugar de los&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #666666;&quot;&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;datos se pone {}&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #666666;&quot;&gt;//modificar datos de la tabla esto se puede hacer directamente desde la tabla, pero lo haremos con el modelo&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #38761d;&quot;&gt;modelo&lt;/span&gt;.setValueAt(&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #b45f06;&quot;&gt;&quot;valorNuevo&quot;&lt;/span&gt;,&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #38761d;&quot;&gt;renglon&lt;/span&gt;,&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #38761d;&quot;&gt;columna&lt;/span&gt;);&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; font-family: &#39;Courier New&#39;, Courier, monospace; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; text-align: left;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: white;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #666666;&quot;&gt;//tomar un valor de la tabla ojo:los valores salen en forma de object por lo que se necesitan castear&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; font-family: &#39;Courier New&#39;, Courier, monospace; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; text-align: left;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: white;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #666666;&quot;&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/span&gt;Object&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #666666;&quot;&gt;&amp;nbsp;&lt;/span&gt;variable = &lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #38761d;&quot;&gt;modelo&lt;/span&gt;.getValueAt(&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #38761d;&quot;&gt;renglon&lt;/span&gt;,&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #38761d;&quot;&gt;columna&lt;/span&gt;);&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; font-family: &#39;Courier New&#39;, Courier, monospace; font-size: small; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; text-align: left;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; text-align: left;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: inherit;&quot;&gt;Y listo tenemos una tabla&amp;nbsp;&lt;/span&gt;dinámica&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: inherit;&quot;&gt;&amp;nbsp;;)&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; text-align: left;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: inherit;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; text-align: left;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: inherit;&quot;&gt;de cualquier forma dejo el&amp;nbsp;&lt;/span&gt;código&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: inherit;&quot;&gt;&amp;nbsp;de ejemplo en mi pagina &lt;/span&gt;&lt;a href=&quot;http://luismy.espaciogratis.info/&quot; style=&quot;font-family: inherit;&quot;&gt;http://luismy.espaciogratis.info&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; text-align: left;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; text-align: left;&quot;&gt;
bueno, actualice esta entrada, porque me di cuenta de que ya la visitan mas seguido y tenia varios errores de&amp;nbsp;ortografía... bueno cualquier comentario es bienvenido, de todos modos creo que puedo borrar los que no me gusten ;D&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://faq-netbeans.blogspot.com/feeds/565358808368664460/comments/default' title='Comentarios de la entrada'/><link rel='replies' type='text/html' href='http://faq-netbeans.blogspot.com/2011/01/tablas-en-netbeans.html#comment-form' title='4 Comentarios'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2058716862278766723/posts/default/565358808368664460'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2058716862278766723/posts/default/565358808368664460'/><link rel='alternate' type='text/html' href='http://faq-netbeans.blogspot.com/2011/01/tablas-en-netbeans.html' title='Tablas en netbeans'/><author><name>luismi_va</name><uri>http://www.blogger.com/profile/04947152389082524194</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjNKCyHqeRFXP30BejWJUJcbzT-R2MyBv9um7c4rlUdwzcmitrBMGICM1DOwnQp_b8MRULb50PmmYqQlzcrFru6nZPscvde0Jtgk2CAbOsDYl7Pl-YzOpQUX39CFdIyC21Wp3QP2jMWA_lj/s72-c/EjemplosBlog0.png" height="72" width="72"/><thr:total>4</thr:total></entry></feed>