New DisplayMode(...)faz os componentes e o background ficarem invísivel ou messed até Mudar de Frame

0 respostas
gregowbr

Bom eu estou utilizando uma aplicação que muda o Display para 1024x768 para se ajustar perfeitamente com os componentes.
Mas toda vez que eu abro o programa (ou vou para outra janela e volto para a janela) e o Display É ajustado para 1024x768, Ele deixa uns componentes invisíveis, muda algumas coisas, como se tivesse dado um bug no vídeo e não gera nenhum erro, e somente quando eu mudo de frame ele ajusta tudo e mesmo a que estava bugada fica normal.
Como resolver o problema? Eu adaptei em um código simples para ficar mais fácil a compreensão!

import javax.swing.*;
import java.awt.*;


public class TestFullScreen {

  public static void main(String[] args) {

    final JTextPane pane = new JTextPane();
    pane.insertComponent(new JButton("Click Me"));

    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.getContentPane().add(pane, BorderLayout.NORTH);
    frame.setSize(360, 180);
    
    frame.setVisible(true);
    

    AtivarFullScreen(frame);
  }
    public static void AtivarFullScreen(Frame f){
        GraphicsDevice device  = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();;

     if(device.getDisplayMode().getHeight() != 768 || device.getDisplayMode().getWidth() != 1024){
    if ( device.isFullScreenSupported() ) {

      device.setFullScreenWindow(f);
      if (device.isDisplayChangeSupported()) {


          System.out.println("Height Tela Atual -> "+device.getDisplayMode().getHeight()+ " Width ->"+device.getDisplayMode().getWidth());


          device.setDisplayMode(
           new DisplayMode( 1024, 768,
                            16, // bitDepth - 8 bits 256 colors
                            DisplayMode.REFRESH_RATE_UNKNOWN ));
      }
      else {
            System.err.println("Change display mode not supported");
          }
    }else {
      System.err.println("Full screen not supported");
    }
    }else{
        System.out.println("Already 1024x768");
    }
    }
  
}

Obrigado aí! :slight_smile:

Criado 9 de dezembro de 2009
Respostas 0
Participantes 1