Dolcezeus
13-05-2010, 08:59
cari amici devo sviluppare in java un gioco che stia in un JFrame a tutto schermo.. ma ho problemi con il layout manager del JPanel che ho piazzato all'interno.
private void initGUI() {
try {
getContentPane().setLayout(new BorderLayout());
setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
this.setExtendedState(Frame.MAXIMIZED_BOTH);
this.setFocusTraversalPolicyProvider(true);
{
background = new JPanel();
background.setBackground(Color.blue);
background.setLayout(new BorderLayout());
background.setVisible(true);
getContentPane().add(background);
}
{
System.out.println(background.getSize().toString());
btStart = new JButton("Start");
btStart.setVisible(true);
btStart.setSize(200, 120);
btStart.setMaximumSize(new Dimension (200,120));
btStart.setMinimumSize(new Dimension (200,120));
btStart.setIgnoreRepaint(true);
background.add(btStart);
}
} catch (Exception e) {
e.printStackTrace();
}
}
il problema è che il bottone start viene massimizzato mentre dovrebbe restare delle dimensioni richieste. ho provato anche a mettere il layoout manager a null e centrare il bottone prelevando le dimensioni del JPanel ma il comando background.getSize(); mi ritorna 0 0 come fare?
private void initGUI() {
try {
getContentPane().setLayout(new BorderLayout());
setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
this.setExtendedState(Frame.MAXIMIZED_BOTH);
this.setFocusTraversalPolicyProvider(true);
{
background = new JPanel();
background.setBackground(Color.blue);
background.setLayout(new BorderLayout());
background.setVisible(true);
getContentPane().add(background);
}
{
System.out.println(background.getSize().toString());
btStart = new JButton("Start");
btStart.setVisible(true);
btStart.setSize(200, 120);
btStart.setMaximumSize(new Dimension (200,120));
btStart.setMinimumSize(new Dimension (200,120));
btStart.setIgnoreRepaint(true);
background.add(btStart);
}
} catch (Exception e) {
e.printStackTrace();
}
}
il problema è che il bottone start viene massimizzato mentre dovrebbe restare delle dimensioni richieste. ho provato anche a mettere il layoout manager a null e centrare il bottone prelevando le dimensioni del JPanel ma il comando background.getSize(); mi ritorna 0 0 come fare?