Visualizzazione dei risultati da 1 a 3 su 3
  1. #1
    Utente di HTML.it L'avatar di mist3r0
    Registrato dal
    Mar 2007
    Messaggi
    103

    JLaben in posizione centrale centrale

    Salve ragazzi, ho un piccolo problema, ho fatto questa JDialog,

    inserendo delle JLabel e facendole scorrere dal basso verso l'alto.

    Il mio problema sta nel fatto che non riesco a metterle centralmente una sotto l'altra!!

    Come posso fare??

    Ho provato anche a settare il FlowLayout e all'intorno del "for" ad ogni componente fare "pannello.add(labels[i],FlowLayout.Center);" ma niente non va!!

    Per favore mi date una mano??

    :master:


    codice:
    package Uno;
    import java.awt.*;
    
    import javax.swing.*;
    import java.awt.event.*;
    import java.io.*;
    import java.awt.font.*;
    import javax.imageio.ImageIO;
    /**
     * 
    
    Title: GiuocoUno</p>
     *
     * 
    
    Description: </p>
     *
     * 
    
    Copyright: Copyright (c) 2006</p>
     *
     * 
    
    Company: </p>
     *
     * @author  * @version 1.0
     */
    public class AboutUnoGameCard {
    
        public static void main(String[] args) {
        	PrimoFrame pf= new PrimoFrame();
          //  pf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            pf.setVisible(true);
            pf.esegui();
    
        }
    }
    //  FRAME INFORMAZIONI SOFTWARE
        class PrimoFrame extends JDialog {
    
        	protected Color background = Color.BLACK;
        	protected Container content;
        	protected JPanel pannello;
        	protected int y;
        	protected boolean attiva;
            protected JLabel labels[];
            protected Toolkit kit;
            
            public PrimoFrame() {
            	kit = Toolkit.getDefaultToolkit();
                int l = 375;
                int h = 200;
                setSize(h, l);
                setLocation(520, 200);
                 //this.setAlwaysOnTop(true);
                Image img = kit.getImage("classes/Images/"+"Icon.jpg");
                setIconImage(img);
                setTitle("About Game");
                labels= new JLabel[15];
                
                labels[0] = new JLabel(" UNO GAME JAVA VERSION ");
                labels[1] = new JLabel(" ");
                labels[2] = new JLabel(" Realizzad By: ");
                labels[3] = new JLabel(" B. G.");
                labels[4] = new JLabel(" altre info");
                labels[5] = new JLabel(" ");
                labels[6] = new JLabel(" Progetto per ");
                labels[7] = new JLabel("");
                labels[8] = new JLabel(" Gioco di carte "); 
                labels[9] = new JLabel(" ");
                labels[10] = new JLabel(" fgsdgdf ");
                labels[11] = new JLabel("");
                labels[12] = new JLabel(" fsdfsd");
                labels[13] = new JLabel("");
                labels[14] = new JLabel(" Data: Dicembre 2007 ");
                content = this.getContentPane();
    
                this.addWindowListener(new WindowAdapter() {
                  public void windowClosing(WindowEvent e) {
                    disattiva();
                  }
                });
    
                this.setBackground(background);
    
                setResizable(false);
                content.setBackground(background);
                
                
                pannello = new JPanel();
                
               pannello.setBackground(background);
               //pannello.setLayout(null);
               
               
         
                for(int i=0; i<labels.length; i++) {
                  labels[i].setForeground(Color.WHITE);
                  pannello.add(labels[i]);
                }
    
                content.add(pannello);
              }
    
              public void disattiva() {
                attiva = false;
              }
    
              public void shift() {
                Dimension d = pannello.getPreferredSize();
                y=content.getHeight();
                while(attiva) {
                  y--;
                  if(y<-d.height)
                    y=content.getHeight();
                  int x = (content.getWidth()- d.width)/2;
                  if(x<0)
                    x=0;
                  pannello.doLayout();
                  pannello.setBounds(x, y, d.width, d.height);
                  try {
                    Thread.sleep(30);
                  }
                  catch (InterruptedException ex) {
                  }
                }
              }
              
              public void esegui(){
            	  attiva = true;
            	    new Thread() {
            	      public void run() {
            	        shift();
            	      }
            	    }.start();
            	  }
            	  
              }
    M|$T3R®

  2. #2
    Utente di HTML.it
    Registrato dal
    Dec 2005
    Messaggi
    16
    e usare il gridlayout invece che il flowlayout?e setti la label centrale..?

  3. #3
    Utente di HTML.it L'avatar di mist3r0
    Registrato dal
    Mar 2007
    Messaggi
    103
    Ho provato! è la stessa cosa! mi mette solo l'ultima label centrale, e le altre nn le fa vedere, puoi fare copia e incolla del codice k ho scritto e provare tu!!
    M|$T3R®

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.