Results 1 to 8 of 8
- 05-19-2009, 02:36 AM #1
Member
- Join Date
- Apr 2009
- Posts
- 11
- Rep Power
- 0
[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:
when i lunch the class Finestra i just see a little window and nothing else...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); } }
Thanks in advance for help!!!
- 05-19-2009, 03:11 AM #2
Don't forget to mark threads as [SOLVED] and give reps to helpful posts.
How To Ask Questions The Smart Way
-
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.
- 05-19-2009, 05:35 AM #4
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
- 05-19-2009, 12:40 PM #5
Member
- Join Date
- Apr 2009
- Posts
- 11
- Rep Power
- 0
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
i forgot to add the panel "destro"Java Code:---- public Pannellodestro() { JPanel destro = new JPanel(new BorderLayout()); ----
- 05-21-2009, 04:21 AM #6
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
You can find another useful constructor for BorderLayout as well, handling the space between controls.
- 05-21-2009, 06:13 PM #7
Member
- Join Date
- Apr 2009
- Posts
- 11
- Rep Power
- 0
"You can find another useful constructor for BorderLayout as well, handling the space between controls."
Eranga you means with the costructor " BorderLayout()"
- 05-22-2009, 03:57 AM #8
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
I\m talking about this.
BorderLayout (Java 2 Platform SE v1.4.2)Java Code:BorderLayout(int hgap, int vgap)
Similar Threads
-
[SOLVED] my programm doesn´t run like it shoud be.
By AlejandroPe in forum New To JavaReplies: 3Last Post: 04-07-2009, 12:42 PM -
[SOLVED] Possible to have two BoxLayout in same area of BorderLayout?
By mainy in forum AWT / SwingReplies: 4Last Post: 02-16-2009, 09:52 PM -
How to Connect Share Point Using Java
By jazz2k8 in forum New To JavaReplies: 7Last Post: 07-15-2008, 06:39 PM -
Got an Idea, Just Share it!
By james in forum Java SoftwareReplies: 0Last Post: 03-18-2008, 12:09 PM -
HashMap to share OutputStream
By gabriel in forum Advanced JavaReplies: 1Last Post: 08-06-2007, 05:47 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks