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

    Default [SOLVED] I share BoxLayout with Conteiner but it doesn' t work

    Hi know that BoxLayout need to be shared with a Conteiner(JFrame),but so i don't see the panel inside.I put my codes so you understand better:

    Java Code:
       package grafica;
    
    import java.awt.GridBagLayout;
    
    
    public class Finestra {
    
    	/**
    	 * @author Carmine
    	 */
    	public static void main(String[] args) {
    		Start finestraApplicazione = new Start();
    		finestraApplicazione.setVisible(true);
    	}
    
    }
    
    
    package grafica;
    
    import java.awt.Container;
    import java.awt.Dimension;
    import java.awt.event.*;
    import java.io.FileInputStream;
    import java.io.FileOutputStream;
    import java.io.IOException;
    import java.io.ObjectInputStream;
    import java.io.ObjectOutputStream;
    
    import java.awt.BorderLayout;
    import java.awt.Dimension;
    import java.awt.GridLayout;
    
    import javax.swing.Box;
    import javax.swing.BoxLayout;
    import javax.swing.JComboBox;
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JPanel;
    import javax.swing.JScrollPane;
    import javax.swing.JTextField;
    import javax.swing.SwingConstants;
    
    
    public class Start extends JFrame {
    	
    	private Pannellodestro pannellodestro;
    	private ListaRosa lista;
    	private FinestraFormazione ff;	
    	
    	
    		public Start(){
    		  super("Gestione squadra");
    		  setSize(new Dimension(1270,750));
    		  Container cp = getContentPane();
    		
    		  JPanel principale = new JPanel();	
    		  
    		  principale.setLayout(new BoxLayout(principale, BoxLayout.LINE_AXIS));
    		  principale.add(Box.createHorizontalStrut(500));
    	      principale.add(new JLabel("Other stuff goes here"));
    	      principale.add(Box.createHorizontalStrut(400));
    	    
    		  pannellodestro = new Pannellodestro();
    		  JPanel pannellocentrale = new JPanel();
    		  JPanel pannellotabella = new JPanel();
    		
    		  principale.add(pannellodestro);
    		  //principale.add(pannellocentrale);
    		  //principale.add(pannellotabella);
    		  
    		  
    		  cp.setLayout(new BoxLayout(cp, BoxLayout.LINE_AXIS));
    		  cp.add(Box.createHorizontalStrut(500));
    		  //cp.add(new JLabel("Other stuff goes here"));
    		  cp.add(Box.createHorizontalStrut(400));
    		  cp.add(principale);	
    		  
              setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              pack();
              setLocationRelativeTo(null);
              
    	}
    }
    
    package grafica;
    
    import java.util.ArrayList;
    
    import javax.swing.*;
    import javax.swing.SpringLayout;
    import java.awt.*;
    import java.awt.event.*;
    
    import Gestione.*;
    
    public class Pannellodestro extends JPanel {
    	
    	private static final String[] LIST_STRINGS = { 
    	    "Portiere", "Difensore",
    	    "Centrocampista", "Attaccante" 
    	};
    	
    	private static final String NOME_GIOCATORE = "nome giocatore";
    	private static final String SCELTA_RUOLO = "scelta ruolo";
    	private static final int COMBO_COUNT = 25;
    	
    	private JPanel principale = new JPanel();
    	private JComboBox[] list = new JComboBox[COMBO_COUNT];
    	private JTextField[] nGiocatori = new JTextField[COMBO_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 Pannellodestro() {
    		
    	    JPanel destro = new JPanel(new BorderLayout());
    		JPanel gridPanel = new JPanel(new GridLayout(0, 2, 0, 0));
    	    JPanel topPanel = new JPanel(new  GridLayout(0, 2, 0, 0));
    	    JPanel bottomPanel = new JPanel(new GridLayout(0, 2, 0, 0));
    	    
    	   
    	    
    	    topPanel.add(new JLabel(NOME_GIOCATORE, SwingConstants.CENTER));
    	    topPanel.add(new JLabel(SCELTA_RUOLO, SwingConstants.CENTER));
    	    
    	    for (int i = 0; i < list.length; i++) {
    	      nGiocatori[i] = new JTextField(5);
    	      list[i] = new JComboBox(LIST_STRINGS);
    	      list[i].setEditable(false);
    	      
    	      gridPanel.add(nGiocatori[i]);
    	      gridPanel.add(list[i]);
    	    }
    	   
    	    bottomPanel.add(new JButton("Salva Rosa"));
    	    bottomPanel.add(new JButton("Carica Rosa"));
    	    
    	    JScrollPane gridScroll = new JScrollPane(gridPanel);
    	    Dimension gsSize = gridScroll.getPreferredSize();
    	    gridScroll.setPreferredSize(new Dimension(gsSize.width + 15, 500));
    	    
    	    
    	    destro.add(topPanel, BorderLayout.PAGE_START);
    	    destro.add(gridScroll, BorderLayout.CENTER);
    	    destro.add(bottomPanel,BorderLayout.SOUTH);
    	    
    }	    
    
    }
    when i lunch the class Finestra i just see a little window and nothing else...

    Thanks in advance for help!!!

  2. #2
    OrangeDog's Avatar
    OrangeDog is offline Senior Member
    Join Date
    Jan 2009
    Location
    Cambridge, UK
    Posts
    838
    Rep Power
    6

  3. #3
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    I gave you the link for the layout manager tutorials just yesterday. I strongly urge you to read them and to study them before venturing forward. This would include studying and running the sample programs that come with the tutorials. Best of luck.

  4. #4
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    Quote Originally Posted by Fubarable View Post
    I gave you the link for the layout manager tutorials just yesterday. I strongly urge you to read them and to study them before venturing forward. This would include studying and running the sample programs that come with the tutorials. Best of luck.
    OP, please pay your attention on this. We couldn't see any effort on what Fubarable says in a previous thread, about the layout. He gives you a nice link, all about the layouts. All what you need is there.

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

    Default

    You are right...but before i put post i had read link about Tutorial of BorderLayout...but i'dont turn out to found mistake.Now i'm solved it...it was simple that in the costructor

    Java Code:
    ----
     public Pannellodestro() {
    		
    	    JPanel destro = new JPanel(new BorderLayout());
    
    ----
    i forgot to add the panel "destro"

  6. #6
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    You can find another useful constructor for BorderLayout as well, handling the space between controls.

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

    Default

    "You can find another useful constructor for BorderLayout as well, handling the space between controls."

    Eranga you means with the costructor " BorderLayout()"

  8. #8
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

Similar Threads

  1. [SOLVED] my programm doesn´t run like it shoud be.
    By AlejandroPe in forum New To Java
    Replies: 3
    Last Post: 04-07-2009, 12:42 PM
  2. Replies: 4
    Last Post: 02-16-2009, 09:52 PM
  3. How to Connect Share Point Using Java
    By jazz2k8 in forum New To Java
    Replies: 7
    Last Post: 07-15-2008, 06:39 PM
  4. Got an Idea, Just Share it!
    By james in forum Java Software
    Replies: 0
    Last Post: 03-18-2008, 12:09 PM
  5. HashMap to share OutputStream
    By gabriel in forum Advanced Java
    Replies: 1
    Last Post: 08-06-2007, 05:47 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
  •