2014-02-17 4 views
1
import javax.swing.JDialog; 
import javax.swing.JFrame; 
import javax.swing.UIManager; 
import javax.swing.UnsupportedLookAndFeelException; 

public class Frame { 

    private JFrame jFrame; 

    public Frame() { 
     try { 
      UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName()); 
      JFrame.setDefaultLookAndFeelDecorated(true); 
      JDialog.setDefaultLookAndFeelDecorated(true); 
     } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException e) { 
      e.printStackTrace(); 
     } 
    } 

    private void create() { 
     jFrame = new JFrame("frame"); 
     jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 
     jFrame.setSize(200, 200); 
     jFrame.setVisible(true); 
    } 

    public static void main(String[] args) { 
     new Frame().create(); 
    } 

} 

위의 코드는 정상적으로 작동하지만 jFrame.undecorated를 true로 설정하면 프레임이 제거되지 않습니까? 아무도 왜 안 알아요? 감사.setUndecorated가 기본이 아닌 모양과 느낌으로 작동하지 않습니다.

편집 : 또한 jFrame.undecorated를 false로 설정하면 기본 룩앤필을 가진 다른 프레임도 표시된다는 것을 발견했습니다. 이처럼 :

example

+0

제발 제 질문은 - Win8 & Java7 에서요? – mKorbel

+0

롤, 예. mts mts – user1009569

+1

AFAIK [Java7에서 투명성 및 장식되지 않은 컨테이너 (OS는 중요하지 않음)]와 관련된 문제가 있음] (http://stackoverflow.com/questions/16219111/cant-transparent-and-undecorated-jframe-in-jdk7- when-enabling-nimbus) – mKorbel

답변

1

는 setUndecorated() 메소드에 대한 문서를 확인하십시오 - 때 볼뿐만 아니라 호출 할 수 있습니다. 두 호출을 사용하는 코드가 생성자에서 주석 처리되었지만 jFrame.setUndecorated (true)가 추가되었습니다. setVisible() 호출 전에

import javax.swing.JDialog; 
import javax.swing.JFrame; 
import javax.swing.UIManager; 
import javax.swing.UnsupportedLookAndFeelException; 

public class Frame { 

private JFrame jFrame; 

public Frame() { 
    try { 
       UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName()); 
     //JFrame.setDefaultLookAndFeelDecorated(true); 
     //JDialog.setDefaultLookAndFeelDecorated(true); 

    } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException e) { 
     e.printStackTrace(); 
    } 
} 

private void create() { 
    jFrame = new JFrame("frame"); 
    jFrame.setUndecorated(true); 
    jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 
    jFrame.setSize(200, 200); 
    jFrame.setVisible(true); 

} 

public static void main(String[] args) { 
    new Frame().create(); 
} 

} 
+0

예 볼 수 없다는 것을 알고있었습니다. JFrame.setDefaultLookAndFeelDecorated (true)를 사용하여. JFrame은 모양과 느낌을 표시하지 않습니다. 또한 setUndCorated (true)가 작동하지 않는 버튼을 클릭하여 프레임을 제거 할 수 있기를 원합니다. – user1009569

+0

그래서 프레임을 최소화하는 것과 같은 일을한다면 undecorated로 설정하면 여전히 '보이지 않는'것으로 간주됩니까? 추측은하지 만 시도 할 가치가 있습니다. – mikemil

+0

위의 그림에서 볼 수 있듯이 표시되지 않은 플래그를 true로 설정하면 표시 여부와 관계없이 프레임이 제거되지 않습니다. – user1009569

관련 문제