Visualizzazione dei risultati da 1 a 4 su 4

Discussione: immagini sovrapposte

  1. #1
    Utente di HTML.it
    Registrato dal
    Jun 2008
    Messaggi
    7

    immagini sovrapposte

    Salve ho un problema:
    ho un JTree con delle directory, e vorrei visualizzare il contenuto dei file. però ho un problema mi sovrappone le immagini come posso risolvere questo problema?
    codice:
    public void cornice(String path, GridBagConstraints lim, GridBagLayout layout) throws IOException, URISyntaxException{	
    //	 	Component c18 = new JLabel(new ImageIcon("ciao"));
    		Component c18 = null;
    		String strFolderPath = null;
    		String strFileName = null;
    		File imagePath=null;
    		BufferedImage image=null ;
    		if(path==null)
    			{
    			strFolderPath = "C:/prova";                
    		    strFileName = "vuota.jpg";  
    		    imagePath = new File(strFolderPath, strFileName);  
    			} 
    		else
    			{
    			ArrayList<String> ris = scomponipath(path);
    			imagePath = new File(ris.get(1), ris.get(0)); 
    			}
    		// Contiene il riferimento al file da aprire	
    		System.out.println(path);
    		image = ImageIO.read(imagePath);	
    		ImageIcon I = new ImageIcon(image);
    		c18 = new JLabel(I);
    		c18.setBackground(Color.white);
    
    		lim.gridx = 0;
    		lim.gridy = 2;
    		lim.gridwidth = 14;
    		lim.gridheight = 2;
    		lim.fill = GridBagConstraints.CENTER;	
    		layout.setConstraints(c18, lim);
    		remove(c18);
    		add(c18);	
    }

  2. #2
    Utente di HTML.it
    Registrato dal
    Aug 2002
    Messaggi
    8,013
    Tiro ad indovinare perché non posti l'intero meccanismo (e se lo dovessi fare, usa i tag CODE, come previsto da etica del forum). L'unica cosa che si capisce è che c18 l'aggiungi sempre nello stesso posto... non vari mai gridx e gridy. Quindi suppongo che se tale metodo viene richiamato più volte...
    <´¯)(¯`¤._)(¯`»ANDREA«´¯)(_.¤´¯)(¯`>
    "The answer to your question is: welcome to tomorrow"

  3. #3
    Utente di HTML.it
    Registrato dal
    Jun 2008
    Messaggi
    7
    codice:
    public void dir(final GridBagConstraints lim, final GridBagLayout layout){
    	DefaultMutableTreeNode top = new DefaultMutableTreeNode("C:\\prova");
    	final JTree c17 = new JTree(top);
    	c17.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
    	c17.addTreeSelectionListener(new TreeSelectionListener(){
    		public void valueChanged(TreeSelectionEvent event){
    			node =  (DefaultMutableTreeNode) c17.getLastSelectedPathComponent();
    			File f = new File(node.toString());
    			addChildrens(f.listFiles());
    			if((node.isRoot() || (!node.isLeaf()) )){
    				try {
    					//repaint();
    					cornice(null, lim, layout);
    					//repaint();
    				} catch (IOException e) {
    					// TODO Auto-generated catch block
    					e.printStackTrace();
    				} catch (URISyntaxException e) {
    					// TODO Auto-generated catch block
    					e.printStackTrace();
    				}
    			}else{			
    			try {
    				//repaint();
    				cornice(node.toString(), lim,layout);
    				//repaint();
    			} catch (IOException e) {
    				// TODO Auto-generated catch block
    				e.printStackTrace();
    			} catch (URISyntaxException e) {
    				// TODO Auto-generated catch block
    				e.printStackTrace();
    			}	
    		}}
    	});
    
    	lim.gridx = 0;
    	lim.gridy = 2;
    	lim.gridwidth = 2;
    	lim.gridheight = 2;
    	lim.fill= GridBagConstraints.NORTHEAST;		
    	layout.setConstraints(c17, lim);
    	add(c17);
    }
    //visualizza immagine file
    public void cornice(String path, GridBagConstraints lim, GridBagLayout layout) throws IOException, URISyntaxException{	
    //	 	Component c18 = new JLabel(new ImageIcon("ciao"));
    		Component c18 = null;
    		String strFolderPath = null;
    		String strFileName = null;
    		File imagePath=null;
    		BufferedImage image=null ;
    		if(path==null)
    			{
    			strFolderPath = "C:/prova";                
    		    strFileName = "vuota.jpg";  
    		    imagePath = new File(strFolderPath, strFileName);  
    			} 
    		else
    			{
    			ArrayList<String> ris = scomponipath(path);
    			imagePath = new File(ris.get(1), ris.get(0)); 
    			}
    		// Contiene il riferimento al file da aprire	
    		System.out.println(path);
    		image = ImageIO.read(imagePath);	
    		ImageIcon I = new ImageIcon(image);
    		c18 = new JLabel(I);
    		c18.setBackground(Color.WHITE);
    		repaint();
    //		JLabel l = new JLabel();
    //		OverlayLayout cont = new OverlayLayout((Container) c18);
    //		l.setLayout(cont);
    		lim.gridx = 0;
    		lim.gridy = 2;
    		lim.gridwidth = 14;
    		lim.gridheight = 2;
    		lim.fill = GridBagConstraints.CENTER;	
    		layout.setConstraints(c18,lim);
    		add(c18);	
    		repaint();
    		
    }

  4. #4
    Moderatore di Programmazione L'avatar di LeleFT
    Registrato dal
    Jun 2003
    Messaggi
    17,328
    Originariamente inviato da Andrea1979
    (e se lo dovessi fare, usa i tag CODE, come previsto da etica del forum)
    Che te le scrivono a fare le cose...

    Sistemo io, per questa volta.


    Ciao.
    "Perchè spendere anche solo 5 dollari per un S.O., quando posso averne uno gratis e spendere quei 5 dollari per 5 bottiglie di birra?" [Jon "maddog" Hall]
    Fatti non foste a viver come bruti, ma per seguir virtute e canoscenza

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.