Visualizzazione dei risultati da 1 a 2 su 2
  1. #1
    Utente di HTML.it
    Registrato dal
    Sep 2007
    Messaggi
    9

    [Swingx]JFrame+Jpanel+Jlabel problemi di visualizzazione

    allora qualcuno puo darmi una mano con questo pezzo di codice posto qua la classe......
    codice:
    package grafica;
    
    import java.awt.Dimension;
    import java.awt.FlowLayout;
    import java.awt.GridLayout;
    import java.io.File;
    import java.util.ArrayList;
    import java.util.Iterator;
    import java.util.List;
    import java.util.Vector;
    
    import javax.swing.BoxLayout;
    import javax.swing.ImageIcon;
    import javax.swing.JLabel;
    import javax.swing.JPanel;
    import javax.swing.SwingConstants;
    import javax.swing.SwingUtilities;
    
    import org.jdesktop.swingx.JXPanel;
    
    
    import photobook.Cartella;
    import photobook.Componenti;
    import photobook.Photobook;
    
    public class CenterPanel extends JPanel{
    	JPanel comp;
    	
    	public CenterPanel(){
    		super();
    		setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
    		//setMinimumSize(new Dimension(200, 400));
    		//setMaximumSize(new Dimension(400, 500));
    		FlowLayout layout = new FlowLayout(FlowLayout.LEADING);
    		comp = new JPanel(layout);
    		comp.add(new JLabel("Primo elemento"));
    		createLabel();
    		add(comp);
    		 SwingUtilities.updateComponentTreeUI(comp);
    		repaint();
    		setVisible(true);
    		
    	}
    	
    	public void createLabel() {
    		List<JLabel> label = new ArrayList<JLabel>();
    		JLabel lab;
    		try {
    
    			Iterator it;
    
    		
    			Photobook p = new Cartella(new File("c:/"));
    			int i = 0;
    			Vector<File> listaFile = p.apri();
    
    			if (listaFile == null)
    				System.out.println("si lista vuota");
    			
    			System.out.println(listaFile.capacity() + "lista file e piena"+ listaFile.isEmpty());
    
    			if (listaFile.capacity() > 0) {
    				it = listaFile.iterator();
    				System.out.println("sn prima do in lista file add label");
    				do {
    					i++;
    
    					File file = (File) it.next();
    					System.out.print("stampo file " + file.toString());
    
    					ImageIcon icon = null;
    					if (file.isDirectory()) {
    						icon = new ImageIcon("icon/paste.gif");
    					}
    					lab = new JLabel("File indice = " + i);
    					comp.add(lab);
    
    					System.out.println("File indice = " + i + " "+ label.isEmpty() + " " + lab.toString());
    
    				} while (it.hasNext());
    			} else {
    				System.out.println("lista Vuota");
    			}
    
    		} catch (Exception e1) {
    			System.out.println("se verificato un errore");
    			e1.printStackTrace();
    		}
    		System.out.println("sn prima dell'iteretor " + label.isEmpty()+" comp: "+comp.toString());
    		/*
    		 * Iterator< JLabel> it=label.iterator(); if (label.isEmpty()) {
    		 * System.out.println("sono dentro"); do {
    		 * 
    		 * comp.add((JLabel)it.next());
    		 * 
    		 * }while (it.hasNext()); add(comp); }
    		 */
    		add(comp);
    	}
    
    }
    le println stampano questo
    codice:
    20lista file e pienafalse
    sn prima do in lista file add label
    stampo file c:\$AVGFile indice = 1 true javax.swing.JLabel[,0,0,0x0,invalid,alignmentX=0.0,alignmentY=0.0,border=,flags=8388608,maximumSize=,minimumSize=,preferredSize=,defaultIcon=,disabledIcon=,horizontalAlignment=LEADING,horizontalTextPosition=TRAILING,iconTextGap=4,labelFor=,text=File indice = 1,verticalAlignment=CENTER,verticalTextPosition=CENTER]
    stampo file c:\$Recycle.BinFile indice = 2 true javax.swing.JLabel[,0,0,0x0,invalid,alignmentX=0.0,alignmentY=0.0,border=,flags=8388608,maximumSize=,minimumSize=,preferredSize=,defaultIcon=,disabledIcon=,horizontalAlignment=LEADING,horizontalTextPosition=TRAILING,iconTextGap=4,labelFor=,text=File indice = 2,verticalAlignment=CENTER,verticalTextPosition=CENTER]
    stampo file c:\aa700fffd888e8b442bb88File indice = 3 true javax.swing.JLabel[,0,0,0x0,invalid,alignmentX=0.0,alignmentY=0.0,border=,flags=8388608,maximumSize=,minimumSize=,preferredSize=,defaultIcon=,disabledIcon=,horizontalAlignment=LEADING,horizontalTextPosition=TRAILING,iconTextGap=4,labelFor=,text=File indice = 3,verticalAlignment=CENTER,verticalTextPosition=CENTER]
    stampo file c:\AeriaGamesFile indice = 4 true javax.swing.JLabel[,0,0,0x0,invalid,alignmentX=0.0,alignmentY=0.0,border=,flags=8388608,maximumSize=,minimumSize=,preferredSize=,defaultIcon=,disabledIcon=,horizontalAlignment=LEADING,horizontalTextPosition=TRAILING,iconTextGap=4,labelFor=,text=File indice = 4,verticalAlignment=CENTER,verticalTextPosition=CENTER]
    stampo file c:\AsgardROFile indice = 5 true javax.swing.JLabel[,0,0,0x0,invalid,alignmentX=0.0,alignmentY=0.0,border=,flags=8388608,maximumSize=,minimumSize=,preferredSize=,defaultIcon=,disabledIcon=,horizontalAlignment=LEADING,horizontalTextPosition=TRAILING,iconTextGap=4,labelFor=,text=File indice = 5,verticalAlignment=CENTER,verticalTextPosition=CENTER]
    stampo file c:\Config.MsiFile indice = 6 true javax.swing.JLabel[,0,0,0x0,invalid,alignmentX=0.0,alignmentY=0.0,border=,flags=8388608,maximumSize=,minimumSize=,preferredSize=,defaultIcon=,disabledIcon=,horizontalAlignment=LEADING,horizontalTextPosition=TRAILING,iconTextGap=4,labelFor=,text=File indice = 6,verticalAlignment=CENTER,verticalTextPosition=CENTER]
    stampo file c:\Documents and SettingsFile indice = 7 true javax.swing.JLabel[,0,0,0x0,invalid,alignmentX=0.0,alignmentY=0.0,border=,flags=8388608,maximumSize=,minimumSize=,preferredSize=,defaultIcon=,disabledIcon=,horizontalAlignment=LEADING,horizontalTextPosition=TRAILING,iconTextGap=4,labelFor=,text=File indice = 7,verticalAlignment=CENTER,verticalTextPosition=CENTER]
    stampo file c:\DownloadsFile indice = 8 true javax.swing.JLabel[,0,0,0x0,invalid,alignmentX=0.0,alignmentY=0.0,border=,flags=8388608,maximumSize=,minimumSize=,preferredSize=,defaultIcon=,disabledIcon=,horizontalAlignment=LEADING,horizontalTextPosition=TRAILING,iconTextGap=4,labelFor=,text=File indice = 8,verticalAlignment=CENTER,verticalTextPosition=CENTER]
    stampo file c:\eclipseFile indice = 9 true javax.swing.JLabel[,0,0,0x0,invalid,alignmentX=0.0,alignmentY=0.0,border=,flags=8388608,maximumSize=,minimumSize=,preferredSize=,defaultIcon=,disabledIcon=,horizontalAlignment=LEADING,horizontalTextPosition=TRAILING,iconTextGap=4,labelFor=,text=File indice = 9,verticalAlignment=CENTER,verticalTextPosition=CENTER]
    stampo file c:\FOXXGAMESFile indice = 10 true javax.swing.JLabel[,0,0,0x0,invalid,alignmentX=0.0,alignmentY=0.0,border=,flags=8388608,maximumSize=,minimumSize=,preferredSize=,defaultIcon=,disabledIcon=,horizontalAlignment=LEADING,horizontalTextPosition=TRAILING,iconTextGap=4,labelFor=,text=File indice = 10,verticalAlignment=CENTER,verticalTextPosition=CENTER]
    stampo file c:\MSOCacheFile indice = 11 true javax.swing.JLabel[,0,0,0x0,invalid,alignmentX=0.0,alignmentY=0.0,border=,flags=8388608,maximumSize=,minimumSize=,preferredSize=,defaultIcon=,disabledIcon=,horizontalAlignment=LEADING,horizontalTextPosition=TRAILING,iconTextGap=4,labelFor=,text=File indice = 11,verticalAlignment=CENTER,verticalTextPosition=CENTER]
    stampo file c:\Program FilesFile indice = 12 true javax.swing.JLabel[,0,0,0x0,invalid,alignmentX=0.0,alignmentY=0.0,border=,flags=8388608,maximumSize=,minimumSize=,preferredSize=,defaultIcon=,disabledIcon=,horizontalAlignment=LEADING,horizontalTextPosition=TRAILING,iconTextGap=4,labelFor=,text=File indice = 12,verticalAlignment=CENTER,verticalTextPosition=CENTER]
    stampo file c:\ProgramDataFile indice = 13 true javax.swing.JLabel[,0,0,0x0,invalid,alignmentX=0.0,alignmentY=0.0,border=,flags=8388608,maximumSize=,minimumSize=,preferredSize=,defaultIcon=,disabledIcon=,horizontalAlignment=LEADING,horizontalTextPosition=TRAILING,iconTextGap=4,labelFor=,text=File indice = 13,verticalAlignment=CENTER,verticalTextPosition=CENTER]
    stampo file c:\RecoveryFile indice = 14 true javax.swing.JLabel[,0,0,0x0,invalid,alignmentX=0.0,alignmentY=0.0,border=,flags=8388608,maximumSize=,minimumSize=,preferredSize=,defaultIcon=,disabledIcon=,horizontalAlignment=LEADING,horizontalTextPosition=TRAILING,iconTextGap=4,labelFor=,text=File indice = 14,verticalAlignment=CENTER,verticalTextPosition=CENTER]
    stampo file c:\SunFile indice = 15 true javax.swing.JLabel[,0,0,0x0,invalid,alignmentX=0.0,alignmentY=0.0,border=,flags=8388608,maximumSize=,minimumSize=,preferredSize=,defaultIcon=,disabledIcon=,horizontalAlignment=LEADING,horizontalTextPosition=TRAILING,iconTextGap=4,labelFor=,text=File indice = 15,verticalAlignment=CENTER,verticalTextPosition=CENTER]
    stampo file c:\System Volume InformationFile indice = 16 true javax.swing.JLabel[,0,0,0x0,invalid,alignmentX=0.0,alignmentY=0.0,border=,flags=8388608,maximumSize=,minimumSize=,preferredSize=,defaultIcon=,disabledIcon=,horizontalAlignment=LEADING,horizontalTextPosition=TRAILING,iconTextGap=4,labelFor=,text=File indice = 16,verticalAlignment=CENTER,verticalTextPosition=CENTER]
    stampo file c:\UsersFile indice = 17 true javax.swing.JLabel[,0,0,0x0,invalid,alignmentX=0.0,alignmentY=0.0,border=,flags=8388608,maximumSize=,minimumSize=,preferredSize=,defaultIcon=,disabledIcon=,horizontalAlignment=LEADING,horizontalTextPosition=TRAILING,iconTextGap=4,labelFor=,text=File indice = 17,verticalAlignment=CENTER,verticalTextPosition=CENTER]
    stampo file c:\WindowsFile indice = 18 true javax.swing.JLabel[,0,0,0x0,invalid,alignmentX=0.0,alignmentY=0.0,border=,flags=8388608,maximumSize=,minimumSize=,preferredSize=,defaultIcon=,disabledIcon=,horizontalAlignment=LEADING,horizontalTextPosition=TRAILING,iconTextGap=4,labelFor=,text=File indice = 18,verticalAlignment=CENTER,verticalTextPosition=CENTER]
    sn prima dell'iteretor true comp: javax.swing.JPanel[,0,0,0x0,invalid,layout=java.awt.FlowLayout,alignmentX=0.0,alignmentY=0.0,border=,flags=9,maximumSize=,minimumSize=,preferredSize=]
    nn fate caso all'italiano perche lo scritto di fretta doveva farmi capire solo i pezzi di codici se entrava... comunque una cosa importate vorrei chiedere perche 'add(comp) non funziona perche deve aggiungere la lista delle label create al componente jpanel centrale ...pero questo risultato nn riesco ad ottenere ora qua sotto vi metto pure la foto del frame uscito:
    [spoiler]
    [/spoiler]

    nn fate caso alla grafica... perche questo e il primo componetne che ci sto lavornado per intero i menu e le altre cose le ho fatto alla bguona senza neache ascoltatori quidni ci devo rimettere mano

  2. #2
    Utente di HTML.it
    Registrato dal
    Sep 2007
    Messaggi
    9
    sembra ke abbia risolto in parte .... ho tolto l'estensione di jpanel e metto un
    codice:
    public Jpanel getComp(){
         return comp;
    }
    quindi mi prendo comp .. tolto tutte le schivese che nn servono ....
    pero io vorrei usare un box layout al posto di flow layout e fare una visualizzazione alla window del disco

    solo ke usando il boxlayout mi da errore passo questo docei
    BoxLayout layout= new boxlayout(comp, swingutilis.Trainer);

    dove svaglio java mi lancia una eccezione sul box layout

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.