대신 JOptionPane
을 사용하는 대신 JDialog
을 사용하는 것이 좋습니다.
JOptionPane jOptionPane = new JOptionPane("Really do this?", JOptionPane.PLAIN_MESSAGE, JOptionPane.YES_NO_OPTION);
JDialog jDialog = jOptionPane.createDialog("dialog title");
다음 원하는 화면의 경계를 취득하고, 예를 들어, 그것의 중앙에 대화 상자를 배치 할 수있는 특정 화면에이를 표시하려면 :
여기
은 예입니다
Rectangle screenBounds = MouseInfo.getPointerInfo().getDevice().getDefaultConfiguration().getBounds();
int x = (int) screenBounds.getCenterX() - (jDialog.getWidth()/2);
int y = (int) screenBounds.getCenterY() - (jDialog.getHeight()/2);
jDialog.setLocation(x, y);
jDialog.setVisible(true);
확인 결과 :
Object selectedValue = jOptionPane.getValue();
int dialogResult = JOptionPane.CLOSED_OPTION;
if (selectedValue != null) {
dialogResult = Integer.parseInt(selectedValue.toString());
}
switch (dialogResult) {
case JOptionPane.YES_OPTION:
LOG.info("yes pressed");
break;
case JOptionPane.NO_OPTION:
LOG.info("no pressed");
break;
case JOptionPane.CLOSED_OPTION:
LOG.info("closed");
break;
default:
}