[Gvsig_desarrolladores] Superposición de JPanels

Para todos e para ninguén sergiopinhon en gmail.com
Vie Jun 13 10:46:50 CEST 2008


Hola, acabo de empezar con gvSig y estoy desarrollando una extensión. Mi 
problema es que tengo un panel para la gestión de usuarios y dentro de este 
panel una jTable y otro panel para disponer dentro una serie de botones, pero 
al mover el panel el panel de los botones se superpone a cualquier otra 
ventana que halla en el espacio de trabajo. ¿Es algún tipo de problema 
conocido de gvSig o estoy haciendo algo mal? Dejo el código:

public class GestionUsuariosPanel extends javax.swing.JPanel implements 
IWindow{

	private static final long serialVersionUID = -2659163430220210188L;
	private final static boolean debug = true;
	private JScrollPane sPusuarios;
	private JTable tUsuarios;
	private JButton bModificar;
	private JButton bNuevo;
	private JButton bEliminar;
	private JButton bVisualizar;
	private Panel botonera;
	private static GestionUsuariosPanel gestionUsuariosPanel=null;
	
	/*
	 * Panel---->|
	 * 			 |
	 * 			 |----->JScrollPane----->
	 * 			 |						|
	 * 			 |						|
	 * 			 |						|---->JTable
	 * 			 |
	 * 			 |
	 * 			 |----->Panel----------->
	 * 									 |
	 * 									 |
	 * 									 |---->Botones
	 * 
	 * */
	
	
	public GestionUsuariosPanel() {
		super();
		initGUI();
	}
	
	private void initGUI() {
		try {
			GridBagLayout thisLayout = new GridBagLayout();
			setPreferredSize(new Dimension(400, 300));
			
			if(debug)
				System.out.println("Iniciada la ventana de usuarios");
			thisLayout.rowWeights = new double[] {0.2, 0.2, 0.2, 0.2};
			thisLayout.rowHeights = new int[] {9, 9, 9, 9};
			thisLayout.columnWeights = new double[] {0.2, 0.2};
			thisLayout.columnWidths = new int[] {9, 9};
			this.setLayout(thisLayout);
			this.setMinimumSize(new Dimension(400,300));
			{/*creamos la tabla*/
				ModeloTablaUsuarios modeloUsuarios = new ModeloTablaUsuarios();
				tUsuarios = new JTable(modeloUsuarios);
				modeloUsuarios.anhadeUsuario(new Usuario("Pepe", "","Admin") );
				modeloUsuarios.anhadeUsuario(new Usuario("Paco", "","Consulta") );
				modeloUsuarios.anhadeUsuario(new Usuario("Paula", "","Consulta") );
				modeloUsuarios.anhadeUsuario(new Usuario("Pablo", "","Consulta") );
				modeloUsuarios.anhadeUsuario(new Usuario("Popeye", "","Consulta") );
			}
			
			{/*la metemos dentro de un ScrollPane*/
				sPusuarios = new JScrollPane(this.tUsuarios);
				/*y el jScrollPane dentro del panel principal ocupando 2 columnas y 4 
filas*/
				this.add(sPusuarios, new GridBagConstraints(0, 0, 2, 4, 0.0, 0.0, 
GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(10, 10, 10, 
10), 0, 0));
			}
			{/*creamos una caja para poner dentro los botones*/
				botonera = new Panel();
				botonera.setLayout(new GridBagLayout());
				/*metemos la caja en la columna de la derecha arriba*/
				this.add(botonera, new GridBagConstraints(2, 0, 1, 1, 0.0, 0.0, 
GridBagConstraints.NORTH, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 
0), 0, 0));
				
			}
			{
				bVisualizar = new JButton();
				//this.add(bVisualizar, new GridBagConstraints(2, 0, 1, 1, 0.0, 0.0, 
GridBagConstraints.NORTH, GridBagConstraints.NONE, new Insets(10, 10, 10, 
10), 0, 0));
				botonera.add(bVisualizar, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0, 
GridBagConstraints.NORTH, GridBagConstraints.BOTH, new Insets(10, 10, 10, 
10), 0, 0));
				//botonera.add(bVisualizar);
				bVisualizar.setText("Visualizar");
			}
			{
				bModificar = new JButton();
				//this.add(bModificar, new GridBagConstraints(2, 0, 1, 1, 0.0, 0.0, 
GridBagConstraints.NORTH, GridBagConstraints.CENTER, new Insets(10, 10, 10, 
10), 0, 0));
				botonera.add(bModificar, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0, 
GridBagConstraints.NORTH, GridBagConstraints.BOTH, new Insets(10, 10, 10, 
10), 0, 0));
				//botonera.add(bModificar);
				bModificar.setText("Modificar");
			}
			{
				bEliminar = new JButton();
				//this.add(bEliminar, new GridBagConstraints(2, 2, 1, 1, 0.0, 0.0, 
GridBagConstraints.NORTH, GridBagConstraints.NONE, new Insets(10, 10, 10, 
10), 0, 0));
				botonera.add(bEliminar, new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0, 
GridBagConstraints.NORTH, GridBagConstraints.BOTH, new Insets(10, 10, 10, 
10), 0, 0));
				//botonera.add(bEliminar);
				bEliminar.setText("Eliminar");
			}
			{
				bNuevo = new JButton();
				//this.add(bNuevo, new GridBagConstraints(2, 3, 1, 1, 0.0, 0.0, 
GridBagConstraints.NORTH, GridBagConstraints.NONE, new Insets(10, 10, 10, 
10), 0, 0));
				botonera.add(bNuevo, new GridBagConstraints(0, 3, 1, 1, 0.0, 0.0, 
GridBagConstraints.NORTH, GridBagConstraints.BOTH, new Insets(10, 10, 10, 
10), 0, 0));
				//botonera.add(bNuevo);
				bNuevo.setText("Nuevo");
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	


	public WindowInfo getWindowInfo() {
		WindowInfo m_viewInfo = new WindowInfo(WindowInfo.RESIZABLE);
		m_viewInfo.setWidth(400);
		m_viewInfo.setHeight(300);
		
		m_viewInfo.setTitle(PluginServices.getText(this,"Gestión de usuarios"));
		return m_viewInfo;
	}
	
	
	public static void main(String[] args) {
		JFrame frame = new JFrame();
		frame.getContentPane().add(new GestionUsuariosPanel());
		frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
		frame.pack();
		frame.setVisible(true);
	}


}


Muchas gracias.



Más información sobre la lista de distribución gvSIG_desarrolladores