Foro de elhacker.net

Programación => Java => Mensaje iniciado por: Juanma91 en 5 Marzo 2014, 03:27 am



Título: Manera eficiente de mostrar datos en jtabbedpane
Publicado por: Juanma91 en 5 Marzo 2014, 03:27 am
Mi error es que a veces carga mis jpanel dentro de mi panel de pestañas pero otras veces no, quiero conseguir que me cargue mis jpanel al clicar una vez en mi nodo


Código:
 int filas = arbol.getRowForLocation(e.getX(), e.getY());
                TreePath ruta = arbol.getPathForLocation(e.getX(), e.getY());

                Object[] lista = ruta.getPath();

                if (filas != -1) {
                    if (lista[2] instanceof DefaultMutableTreeNode && lista[2] == listadoProducto) {
                        if (e.getClickCount() == 1) {

                            if (isListado == false) {
                                panelListado = new JPanel();
                                panelPestaña.addTab("Listado Producto", panelListado);//añadimos el panel al tabbedPane en una nueva viñeta
                                try {
                                    panelListado.add(new ListadoProducto(Vista.this));
                                } catch (Exception ex) {
                                    System.out.println(ex);
                                }
                                isListado = true;
                            } else {
                                panelListado.removeAll();
                                try {
                                    panelListado.add(new ListadoProducto(Vista.this));
                                } catch (Exception ex) {
                                    System.out.println(ex);
                                }
                                revalidate();
                                repaint();
                            }
                        }
                    } else if (lista[2] instanceof DefaultMutableTreeNode && lista[2] == listadoCategoria) {
                        if (e.getClickCount() == 1) {
                            if (isListado = false) {
                                panelListado = new JPanel();
                                panelPestaña.addTab("Listado Categoria", panelCreacion);
                                try {
                                    panelListado.add(new ListadoCategoría(Vista.this));
                                } catch (Exception er) {
                                    System.out.println(er);
                                }
                                isListado = true;
                            } else {
                                panelListado.removeAll();
                                try {
                                    panelListado.add(new ListadoCategoría(Vista.this));
                                } catch (Exception ex1) {
                                    System.out.println(ex1);
                                }
                                revalidate();
                                repaint();
                            }

                        }
                    } else if (lista[2] instanceof DefaultMutableTreeNode && lista[2] == creacionCategoria) {
                        if(e.getClickCount()==1){
                            if(isCreate==false){
                                panelPestaña.addTab("Creacion Categoria", panelCreacion);
                                panelCreacion.add(new CrearCategoria());
                                isCreate= true;
                            }else{
                                panelPestaña.removeAll();
                                panelCreacion.add(new CrearCategoria());
                                revalidate();
                                repaint();
                            }
                        }

                    } else if (lista[2] instanceof DefaultMutableTreeNode && lista[2] == creacionProducto) {
                        if(e.getClickCount()==1){
                            if(isCreate==false){
                                panelPestaña.addTab("Creacion Producto", panelCreacion);
                                panelCreacion.add(new CrearProducto());
                                isCreate=true;
                            }else{
                               panelPestaña.removeAll();
                               panelCreacion.add(new CrearProducto());
                               revalidate();
                               repaint();
                            }