2011-07-27 5 views
10

Windows 작업 표시 줄의 높이를 동적으로 조정하여 내 응용 프로그램을 전체 화면으로 설정하는 방법을 알 수 없습니다.
아시다시피, 작업 표시 줄은 아래쪽, 위쪽, 왼쪽 또는 오른쪽의 네 가지 위치에있을 수 있습니다. 따라서 창 경계를 설정할 현재 위치를 알 수 있는지 궁금합니다.Windows 작업 표시 줄 높이/너비

편집 :

GraphicsDevice myDevice; 
Window myWindow; 

try { 
    myDevice.setFullScreenWindow(myWindow); 
    ... 
} finally { 
    myDevice.setFullScreenWindow(null); 
} 

그러나 전체 화면 모드에서 실행하도록 응용 프로그램을 원하는 경우에 나는 NullPointerException

+0

Jframe/frame을 사용하고 있습니까? – Pratik

+0

네, 죄송합니다. JFrame을 사용하고 있습니다. – mastaH

답변

5

JFrame을 만들 때. JFrame를 API를

jFrame = new JFrame("TESTER"); 
jFrame.setExtendedState(JFrame.MAXIMIZED_BOTH); 

계정으로 작업 표시 줄의 입장을 자동으로 전체 화면으로 창문을 설정 한 것 MAXIMIZED_BOTH 설정에서 setExtendedState() 방법에 전화를 겁니다. 뿐만 아니라,

int taskbarheight = Toolkit.getDefaultToolkit().getScreenSize().height 
    - GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds().height(); 

또는 사용할 수 있습니다 :

Dimension scrnSize = Toolkit.getDefaultToolkit().getScreenSize(); 
Rectangle winSize = GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds(); 

int taskBarHeight = scrnSize.height - winSize.height; 
+0

이것은 해결책 일 수 있지만, JFrame 전체 화면을 설정하고 "일반"크기로 돌아가는 토글 방법이 필요했습니다. – mastaH

+0

'jFrame.setSize (450,450)'와 같은 기본 크기를 설정 한 후'jFrame.setExtendedState (JFrame.MAXIMIZED_BOTH);를 호출하면 창의 상단에있는 최대화 버튼을 누르면 두 크기 사이를 토글합니다. –

+0

버튼을 사용하여 최대 값과 보통 값 사이를 전환하는 방법은 무엇입니까? – mastaH

2

을 뻥, 당신하여 입력 할 수 있습니다 루카스 링크를 사용하여 나는이 tryied 적절한 GraphicsDevice를 가져오고 setFullScreenWindow(Window)-method 사용 : 더 (그리고 더 완전한) 내용

GraphicsDevice myDevice = GraphicsEnvironment. 
    getLocalGraphicsEnvironment().getDefaultScreenDevice(); 
Window myWindow; 

try { 
    myDevice.setFullScreenWindow(myWindow); 
    ... 
} finally { 
    myDevice.setFullScreenWindow(null); 
} 

. Docs 참조)

+0

지금 확인 중입니다. – mastaH

21

이 필요한 경우 Windows 작업 표시 줄의 높이를 얻을 수있다

JFrame frame = new JFrame(); 
frame.setSize(GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds().getSize(); 
1

당신은 사용할 수 있습니다

0

이 내가 작성한 프로그램의 일부입니다.

public enum Location { 
    TOP, RIGHT, BOTTOM, LEFT; 
} 

private static final class Taskbar { 
    public final Location location; 
    public final int width, height; 

    private Taskbar(Location location, int width, int height) { 
     this.location = location; 
     this.width = width; 
     this.height = height; 
    } 

    public static Taskbar getTaskbar() { 
     Rectangle other = GraphicsEnvironment.getLocalGraphicsEnvironment() 
       .getMaximumWindowBounds(); 
     return new Taskbar(other.x != 0 ? Location.TOP 
       : (other.y != 0 ? Location.LEFT 
         : (other.width == IFrame.width ? Location.BOTTOM 
           : Location.RIGHT)), IFrame.width 
       - other.width, IFrame.height - other.height); 
    } 
} 

본질적 Taskbar.getTaskbar()를 호출하면 그 위치 (TOP, RIGHT, BOTTOM, LEFT), 및 그 폭과 높이 정보를 포함하는 표시 줄을 줄 것이다.

관련 문제