0
버튼 클릭시 JFrame의 중앙에 JDialog를 팝업으로 표시하려고합니다. JOptionPanel 팝업 부모 JFrame 통해 올바르게 있지만 JDialog JFrame 상대적으로 터지는 있지만 중앙 않습니다.JDialog가 부모 JFrame보다 가운데에 있지 않습니다.
버튼은 실제로 내 코드에서 JMenuItem이지만 여기서는 JButton으로 작성하여 쉽고 간편하게 만들었습니다.
JButton about = new JButton("About");
about.addActionListener(new ActionListener() { //this one IS NOT in the center of MyJFrame
public void actionPerformed(ActionEvent e) {
new AboutDialog(MyJFrame.this);
}
});
JButton exit = new JButton("Exit");
exit.addActionListener(new ActionListener() { //this one IS in the center of MyJFrame
public void actionPerformed(ActionEvent e) {
if(JOptionPane.showConfirmDialog(MyJFrame.this, "Are you sure you want to exit ?","",JOptionPane.YES_NO_OPTION) == 0)
System.exit(0);
}
});
AboutDialog 클래스
public class AboutDialog extends JDialog{
public AboutDialog(JFrame parent) {
setLocationRelativeTo(parent);
setLayout(new BorderLayout());
...
: 내 부모 JFrame의에서
전화 : 여기
내 코드입니다는
고맙습니다. 작동합니다. – CMPS