ciao e semibenvenuto sul forum
Primis: usa il tag [*CODE] per postare codice, altrimenti viene una porcheria
Secundis: stai mischiando componenti AWT e SWING, aspettati l'inaspettato.
Per come centrare e settare le dimensioni: prima conviene settare le dimensioni (con setSize) e poi centrare (setLocationRelativeTo(null) è una "scorciatoia"):
codice:import javax.swing.*; /** * * @author Andrea */ public class JFrameCenter extends JFrame { private JLabel label = new JLabel("AL CENTRO"); public JFrameCenter() { super("Test Centratura"); this.setSize(600,200); this.getContentPane().add(label); this.setVisible(true); this.setLocationRelativeTo(null); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } public static void main (String[] args) { new JFrameCenter(); } }

Rispondi quotando