Ver Mensaje Individual
  #1 (permalink)  
Antiguo 28/03/2014, 01:07
AlbertoRC87
 
Fecha de Ingreso: marzo-2014
Ubicación: Madrid
Mensajes: 21
Antigüedad: 10 años, 1 mes
Puntos: 0
JScrollPane no muestra scrollbar

Hola!, estoy creando una aplicación que lee un xml y a raiz de eso creo varios jpanel que contienen una imagen, titulo y descripcion. Estos jpanel los añado a un jpanel padre que es el que guardo en un jscrollpane.
El problema viene porque no me deja la opción de hacer el scroll. Mi teoría es que eso sucede porque los jpanel hijos están posicionados aunque el padre no tenga ni tamaño ni posición.

Este es el código que utilizo:

Código:
JPanel jpanel=functions.createPanels(sShop);
JScrollPane scrollPane = new JScrollPane(jpanel);
		scrollPane.setBorder(new EtchedBorder(EtchedBorder.LOWERED, null, null));
		scrollPane.setBounds(6, 251, 988, 256);
		SearchDevices sd=new SearchDevices();
		getContentPane().add(scrollPane);
La función createPanels
Código:
public JPanel createPanels(String sShop) {
		
		ArrayList<Data> listData = readXml(sShop);
		JPanel jpanel = null;
		JPanel alljpanel = new JPanel();
		//alljpanel.setBounds(6,16,976,1000);
		alljpanel.setLayout(null);
		
		URL url;
		BufferedImage image;
		JLabel lblImage;
		JLabel lblTitle;
		JLabel lblSubtitle;

		int x=6;
		int y=6;

		for (int i=0;i<listData.size();i++) {
			
			try {

	            lblImage = new JLabel();
	            lblImage.setBounds(6, 6, 100, 100);
	            //System.out.println(listApps.get(i).icon);
	            //System.out.println(listApps.get(i).name);
	            //System.out.println(listApps.get(i).category);
				url = new URL(listData.get(i).icon);
				image = ImageIO.read(url);

	            //System.out.println("Load image into frame...");
				lblImage.setIcon(new ImageIcon(image.getScaledInstance(100,100, Image.SCALE_SMOOTH)));
				
				lblTitle=new JLabel(listData.get(i).name);
				lblTitle.setBounds(6, 110, 100, 18);
				lblTitle.setFont(new Font("Calibri", Font.BOLD, 16));
				lblSubtitle=new JLabel(listData.get(i).category);
				lblSubtitle.setBounds(6, 130, 100, 16);
				

				jpanel=new JPanel();
				jpanel.setBounds(x,y,112,152);
				jpanel.setLayout(null);
				
				jpanel.add(lblImage);
				jpanel.add(lblTitle);
				jpanel.add(lblSubtitle);
				if(x<=784) {
					
					x+=112;
					
				} else {
					
					y+=152;
					x=6;
					
				}

			
			
				//System.out.println(x+" "+y+" "+listApps.get(i).name);
				
				alljpanel.add(jpanel);
	            
			} catch (MalformedURLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
            
			
		}
		
		return alljpanel;
		
	}
Saludos!