메뉴를 여는 단추의 y 위치에 따라 JPopupMenu
의 위치를 설정하고 싶습니다. 내 코드는 내 첫 번째 모니터에서 제대로 작동하지만 다른 두 번째 모니터에서는 오류가 발생합니다. getLocationOnScreen()
은 구성 요소가 표시된 실제 화면이 아니라 기본 화면을 기준으로 위치를 전달하는 문제입니다.현재 모니터에서 구성 요소 위치 가져 오기
내 코드 :
// screenSize represents the size of the screen where the button is
// currently showing
final Rectangle screenSize = dateButton.getGraphicsConfiguration().getBounds();
final int yScreen = screenSize.height;
int preferredY;
// getLocationOnScreen does always give the relative position to the main screen
if (getLocationOnScreen().y + dateButton.getHeight() + datePopup.getPreferredSize().height > yScreen) {
preferredY = -datePopup.getPreferredSize().height;
} else {
preferredY = getPreferredSize().height;
}
datePopup.show(DateSpinner.this, 0, preferredY);
이 어떻게 실제 모니터에 구성 요소의 위치를 얻을 수 있나요?
보조 모니터가 반대 위치에 있다면 어떻게 될까요? 기본 및 보조 모니터가 변경되면 어떻게됩니까? – Stefan
"+ ="이 아니어야합니까? –