Fórum Centralizar janelas na tela #568020
09/04/2009
0
public static void center(Component componente)
{
// Centraliza a janela de abertura no centro do desktop.
Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
Rectangle r = componente.getBounds();
// Dimensões da janela
int widthSplash = r.width ;
int heightSplash = r.height;
// calculo para encontrar as cooredenadas X e Y para a centralização da janela.
int posX = (screen.width / 2) - ( widthSplash / 2 );
int posY = (screen.height / 2) - ( heightSplash / 2 );
componente.setBounds(posX,posY,widthSplash,heightSplash);
}
Raphael Costa
Curtir tópico
+ 0Posts
09/04/2009
Gostei + 0
09/04/2009
Deivson Costa
Gostei + 0
09/04/2009
Deivson Costa
Gostei + 0
09/04/2009
Deivson Costa
Gostei + 0
09/04/2009
Deivson Costa
Gostei + 0
09/04/2009
Deivson Costa
Gostei + 0
16/09/2009
Deivson Costa
Gostei + 0
17/09/2009
Deivson Costa
import java.awt.Dimension;
import java.awt.Toolkit;
import javax.swing.ImageIcon;
import javax.swing.JPanel;
import javax.swing.JFrame;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
public class JForm extends JFrame {
private static final long serialVersionUID = 1L;
public static final int CENTER_SCREEN = 0;
public static final int FULL_SCREEN = 1;
private int sHeight;
private int sWidth;
private JPanel jp;
public void setIconImage(String fileName){
ImageIcon ico = new ImageIcon(fileName);
this.setIconImage(ico.getImage());
}
public void setScreen(int screenType){
Toolkit tk = Toolkit.getDefaultToolkit();
Dimension scrSize = tk.getScreenSize();
switch(screenType){
case 0:
this.setSize(this.sWidth,this.sHeight);
int scrWidth = scrSize.width - this.getWidth();
int scrHeight = scrSize.height - this.getHeight();
this.setLocation(scrWidth/2,scrHeight/2);
break;
case 1:
this.setLocation(0,0);
this.setSize(scrSize.width, scrSize.height);
break;
}
}
public void Show(){
this.setVisible(true);
}
public void Close(){
System.exit(0);
}
public JForm(String title,int Height,int Width){
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
this.sHeight = Height;
this.sWidth = Width;
jp = new JPanel(null);
this.setContentPane(jp);
this.setTitle(title);
this.setSize(this.sWidth, this.sHeight);
this.setDefaultCloseOperation(3);
} catch (IllegalAccessException e) {} catch (ClassNotFoundException e) {
} catch (InstantiationException e) {} catch (UnsupportedLookAndFeelException e) {}
}
}
Gostei + 0
18/09/2009
Deivson Costa
Gostei + 0
18/09/2009
Deivson Costa
Gostei + 0