Results 1 to 5 of 5
  1. #1
    Wolverine is offline Member
    Join Date
    Apr 2009
    Posts
    11
    Rep Power
    0

    Default How show a popWindow that have JPanel like parent

    Hi i have some problem to view a popup that have a JPanel like parent.
    My GUI structure are this:

    -the main in a class tha create an object Start.
    -Start(extends JFrame) create 4 istance of the panels and than add them at is Container.
    -ones of this Panel(each extends JPanel):PannelloTabella have some jbutton

    i would like that when the user click on one of this jbutton it show popup menu.
    I put the code for throw popup in the pannel where is the botton,but,i have see API about JDialog and there isn't a costructor that take a JPanel,title and boolean.
    There is just that for something JDialog and frame

    Java Code:
       
    public class Start extends JFrame {
    	
    	private Pannellodestro pannelloDestro;
    	private PannelloControllo pannelloControllo;
    	private PannelloTabella pannelloTabella; 
    	private ListaRosa lista;
    		
    		public Start(){
    		   super("Gestione squadra");
    		   setSize(new Dimension(1270,750));
    		   Container cp = getContentPane();
    			  
    	  	  pannelloDestro = new Pannellodestro();
    		  pannelloControllo = new PannelloControllo();
    		  pannelloTabella = new PannelloTabella();
    		  
    		  cp.add(pannelloDestro,BorderLayout.EAST);
    		  cp.add(pannelloControllo,BorderLayout.NORTH);
    		  cp.add(pannelloTabella,BorderLayout.CENTER);
    		  
    		  
              setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              pack();
              setLocationRelativeTo(null);
              setVisible(true);
              
    	}
    }
    
    
    public class PannelloTabella extends JPanel {
    	
    	private Start start;
    	private AscoltatoreSalvaRosa asc;
    	private Start padre;
    	private FinestraFormazione ff;
    	private final String[] NOMI_COLONNE = {"Nome",
                "Ruolo",
                "Media Voto",
                "Gol fatti/Subiti",
                "Cartellini",
                "Giornate giocate","Formazione"
        };
    	
    	private JButton bottoneAggiorna,bottoneSalva,bottoneFormazione;
    	private  final int TEXT_COUNT = 25;
    	
    	//private JComboBox[] list = new JComboBox[TEXT_COUNT ];
    	private JTextField[][] nGiocatori = new JTextField[TEXT_COUNT][6];
    	private JCheckBox[] selezione=new JCheckBox[TEXT_COUNT]; 
    	/**
    	 * Costruttore che mi realizza i pannelli con le JTextField in cui inserire i nomi dei giocatori e le JComboBox 
    	 * con cui si sceglie il ruolo
    	 * @param  il titolo del pannello corrispondente
    	 */
    	public PannelloTabella() {
    		
    	    JPanel griglia = new JPanel(new BorderLayout());
    		
    	    JPanel pannelloLegenda = new JPanel(new  GridLayout(1, 7,0, 0)); 
    	    JPanel pannelloGriglia = new JPanel(new GridLayout(25, 7,0, 0));
    	    JPanel pannelloBottoni = new JPanel(new GridLayout(0, 2, 0,0));
    	    
    	   	    
    	    for(int k = 0; k <NOMI_COLONNE.length; k++){
    	    	pannelloLegenda.add(new JLabel(NOMI_COLONNE[k],SwingConstants.CENTER));
    	    	
    	    }
    	   	    
    	    for (int i = 0;i < TEXT_COUNT; i++) {
    	       for(int j=0;j<7;j++){ 
    	    	   	    if(j<6){
    	    	   	    nGiocatori[i][j] = new JTextField(1);
    	    		    pannelloGriglia.add(nGiocatori[i][j]);
    	    	        nGiocatori[i][j].setEditable(false);   
    	                }else{
    	                	selezione[i] = new JCheckBox();
    	                	selezione[i].addActionListener(asc);
    	                	pannelloGriglia.add(selezione[i]);
    	                }
    	       }   	    
    	   }
    	    
    	    
    	    bottoneSalva = new JButton("SALVA");
    	    pannelloBottoni.add(bottoneSalva);
    	    bottoneFormazione = new JButton("FORMAZIONE");
    	    pannelloBottoni.add(bottoneFormazione);
    	    
    	    //lancio la FinestraFormazione come popup 
    		
    		bottoneFormazione.addActionListener(new ActionListener(){
    			public void actionPerformed(ActionEvent e){
    				ff = new FinestraFormazione(start);
    				ff.setVisible(true);  
    			}
    		});
    	    
    	    
    	    JScrollPane gridScroll = new JScrollPane(pannelloGriglia);
    	    Dimension gsSize = gridScroll.getPreferredSize();
    	    gridScroll.setPreferredSize(new Dimension(gsSize.width, 500));
    	    
    	    griglia.add(pannelloLegenda, BorderLayout.PAGE_START);
    	    griglia.add(pannelloGriglia, BorderLayout.CENTER);
    	    griglia.add(pannelloBottoni,BorderLayout.PAGE_END);
    	    add(griglia);
    	    
       }
    }
    
    public class FinestraFormazione extends JDialog {
    		
    	
    	private JButton bottoneAggiorna;
    	private Start padre;
    	private final String[] NOMI_COLONNE = {"Nome",
                "Ruolo",
                "Media Voto",
                "Gol fatti/Subiti",
                "Cartellini",
                "Giornate giocate"
        };
    	
    	private JTextField[][] nGiocatori;
    	private  final int TEXT_COUNT = 25;
    		
    	    /**
    		 * Costruttore che mi costruisce la finestra pop-up di aggiornamento dei dati per lo storico
    		 * @param parent  un oggetto di classe Start che viene recuperato
    		 */
    		
    		public FinestraFormazione(Start  p){
    			super(p,"Finestra aggiornamento storico", true);
    			setSize(new Dimension(750,650));
    			padre=p;
    			setLocation(100,40);
    			Container cp = getContentPane();
    			cp.setLayout(new BorderLayout());
    			
    			JPanel pannelloLegenda2 = new JPanel(new  GridLayout(1, 6,0, 0)); 
    		    JPanel pannelloGriglia2 = new JPanel(new GridLayout(25, 6,0, 0));
    		    JPanel pannelloBottoni2 = new JPanel(new GridLayout(1, 0, 0,0));			
    			
    		    bottoneAggiorna = new JButton("AGGIORNA") ;
    		    pannelloBottoni2.add(bottoneAggiorna);
    		    
    		    for(int k = 0; k <NOMI_COLONNE.length; k++){
    		    	pannelloLegenda2.add(new JLabel(NOMI_COLONNE[k],SwingConstants.CENTER));
    		    	
    		    }
    		   	    
    		    for (int i = 0;i < TEXT_COUNT; i++) {
    		        for(int j=0;j<6;j++){ 
    		    	   	    
    		    	   	    nGiocatori[i][j] = new JTextField(3);
    		    		    pannelloGriglia2.add(nGiocatori[i][j]);
    		    	        nGiocatori[i][j].setEditable(true);   
    		                
    		       }   	    
    		   }
    		    
    		    
    		    JScrollPane gridScroll = new JScrollPane(pannelloGriglia2);
    		    Dimension gsSize = gridScroll.getPreferredSize();
    		    gridScroll.setPreferredSize(new Dimension(gsSize.width, 500)); 
    		    
    		    cp.add(pannelloLegenda2, BorderLayout.PAGE_START);
    		    cp.add(pannelloGriglia2, BorderLayout.CENTER);
    		    cp.add(pannelloBottoni2,BorderLayout.PAGE_END);
    		}
    }
    when i click on the jbotton: bottoneFormazione,i have this runtime error:

    Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
    at grafica.FinestraFormazione.<init>(FinestraFormazio ne.java:67)
    at grafica.PannelloTabella$1.actionPerformed(Pannello Tabella.java:75)
    at javax.swing.AbstractButton.fireActionPerformed(Unk nown Source)
    at javax.swing.AbstractButton$Handler.actionPerformed (Unknown Source)
    at javax.swing.DefaultButtonModel.fireActionPerformed (Unknown Source)
    ........
    .....and more

    what the problem?

    thanks a lot for some advice,help

  2. #2
    Michael Dunn is offline Member
    Join Date
    Jul 2008
    Posts
    62
    Rep Power
    0

    Default

    Java Code:
    //private JTextField[][] nGiocatori;
    private  final int TEXT_COUNT = 25;
    private JTextField[][] nGiocatori = new JTextField[TEXT_COUNT][6];

  3. #3
    Wolverine is offline Member
    Join Date
    Apr 2009
    Posts
    11
    Rep Power
    0

    Default

    Sorry Michael what you means?

  4. #4
    Michael Dunn is offline Member
    Join Date
    Jul 2008
    Posts
    62
    Rep Power
    0

    Default

    1)
    private JTextField[][] nGiocatori;
    private final int TEXT_COUNT = 25;

    2)
    //private JTextField[][] nGiocatori;
    private final int TEXT_COUNT = 25;
    private JTextField[][] nGiocatori = new JTextField[TEXT_COUNT][6];

    do you notice anything different between (1) and (2)?

  5. #5
    Wolverine is offline Member
    Join Date
    Apr 2009
    Posts
    11
    Rep Power
    0

Similar Threads

  1. Replies: 2
    Last Post: 12-12-2008, 11:48 PM
  2. Parent & Child window issues......
    By jithan in forum New To Java
    Replies: 2
    Last Post: 09-20-2008, 10:21 AM
  3. netbeans 6.0 not show commpunent or show blank page
    By fahimaamir in forum NetBeans
    Replies: 1
    Last Post: 01-26-2008, 07:20 AM
  4. disable parent window
    By ismailsaleh in forum AWT / Swing
    Replies: 1
    Last Post: 01-08-2008, 12:15 AM
  5. Replies: 0
    Last Post: 08-03-2007, 05:21 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •