2013-06-27 2 views
0

전체 화면 프레임 문제

public class FullScreenFrameTest extends JFrame { 

    public FullScreenFrameTest() { 
     super(); 
     initFrame(); 
     setVisible(true); 

     //full screen 
     GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment(); 
     GraphicsDevice device = env.getDefaultScreenDevice(); 
     device.setFullScreenWindow(this); 
     //end full screen 
    } 

    public void initFrame() { 
     Dimension screen = Toolkit.getDefaultToolkit().getScreenSize(); 
     setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 
     setUndecorated(true); 
     setLocation(0, 0); //tried removing this, still doesn't work 
     setSize(screen.width, screen.height); 
    } 

    public static void main(String[] args) { 
     try { 
      UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); 
     } catch (Exception e) { 
     } 
     new FullScreenFrameTest(); 
    } 
} 

문제는 가끔이 작업을 수행한다는 것입니다 때로는 특히 우분투,하지 않는 나는 기본적으로 새로운 JFrame의를 초기화하고 그것을 전체 화면으로 설정이 코드를 가지고 : 때로는 전체 화면을 볼 때로는 두 개의 막대가 표시됩니다. 나는 무엇을 놓치고 있습니까?

UPDATE

은 스크린 샷이 있습니다 :

Screenshot

+1

['invokeLater()'] (http://docs.oracle.com/javase/tutorial/uiswing/concurrency/initial.html)? –

+2

1) EDT에서 자바 GUI를 생성하고 업데이트해야합니다. 자세한 내용은 [동시성의 동시성] (http://docs.oracle.com/javase/tutorial/uiswing/concurrency/)을 참조하십시오. 2) ['Frame.setExtendedState (int)'] (http://docs.oracle.com/javase/7/docs/api/java/awt/Frame.html#setExtendedState%28int%29)도 참조하십시오. –

+1

@CatalinaIsland 정말 고마워! – BackSlash

답변

1

변경

setLocation(0, 0); //tried removing this, still doesn't work 
setSize(screen.width, screen.height); 

으로
setExtendedState(java.awt.Frame.MAXIMIZED_BOTH); 
setLocationRelativeTo(null); 
,

FullScreenFrameTest() 생성자를 SwingUtilities.invokeLater 내에 호출하십시오.

UPDATE

이 때문에 자바 런타임 환경에서 버그가 수 있습니다. 다음은보고 된 버그입니다 http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=7057287
이 문제에 대해 자세히 알고 싶다면 HERE을보십시오.
UPDATE
tryI 당신이 JFrame#setAlwaysOnTop(true)

+0

작동하지 않고 두 개의 막대를 계속 표시합니다. – BackSlash

+0

스크린 샷을 표시 할 수 있습니까? –

+0

예, 제 업데이트를 참조하십시오 – BackSlash

2

invokeLater()와 이벤트 발송 쓰레드에 GUI를 구축해야합니다 사용하는 제안으로 마지막.

업데이트 : 여기에 일관되게 작동하는 것 같습니다 SSCCE입니다.

import java.awt.EventQueue; 
import java.awt.GraphicsDevice; 
import java.awt.GraphicsEnvironment; 
import javax.swing.JFrame; 
import javax.swing.JLabel; 

public class FullScreenFrameTest extends JFrame { 

    public FullScreenFrameTest() { 
     setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 
     setUndecorated(true); 
     add(new JLabel("Test", JLabel.CENTER)); 
     GraphicsEnvironment env = 
      GraphicsEnvironment.getLocalGraphicsEnvironment(); 
     GraphicsDevice device = env.getDefaultScreenDevice(); 
     device.setFullScreenWindow(this); 
     setVisible(true); 
    } 

    public static void main(String[] args) { 
     EventQueue.invokeLater(new Runnable() { 
      @Override 
      public void run() { 
       new FullScreenFrameTest(); 
      } 
     }); 
    } 
} 
+0

음, 처음에는 작동했지만 이제는 작동하지 않습니다. – BackSlash

+0

'setExtendedState() '를 사용해도? –

+0

예,'setExtendedState (JFrame.MAXIMIZED_BOTH)' – BackSlash