• This is default featured slide 1 title

    Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.This theme is Bloggerized by NewBloggerThemes.com.

  • This is default featured slide 2 title

    Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.This theme is Bloggerized by NewBloggerThemes.com.

  • This is default featured slide 3 title

    Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.This theme is Bloggerized by NewBloggerThemes.com.

  • This is default featured slide 4 title

    Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.This theme is Bloggerized by NewBloggerThemes.com.

  • This is default featured slide 5 title

    Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.This theme is Bloggerized by NewBloggerThemes.com.

Mostrando entradas con la etiqueta pantalla. Mostrar todas las entradas
Mostrando entradas con la etiqueta pantalla. Mostrar todas las entradas

Centrar pantalla de un Jframe en java

Antes de la llagada de jdk 1.4 entrar un frame o jframe en la pantalla era algo tedioso pero ahora les muestro un truco de como evitarse eso.


Antes hacíamos esto:

// Se obtienen las dimensiones en pixels de la pantalla.
Dimension pantalla = Toolkit.getDefaultToolkit().getScreenSize();
// Se obtienen las dimensiones en pixels de la ventana.
Dimension ventana = getSize();
// Una cuenta para situar la ventana en el centro de la pantalla.
setLocation((pantalla.width - ventana.width) / 2,
(pantalla.height - ventana.height) / 2);

Pero la forma "moderna en que lo lograremos sera así" :
JFrame fram = new JFrame();
fram.setLocationRelativeTo(null);
fram.setVisible(true); // Y la ventana se muestra centrada en la pantalla.

Lo unico que se necesito fue pasarle el parametro null y listo nos evitamos mucho codigo
Share:

Visitantes

Flag Counter

Popular Posts

Etiquetas

Recent Posts