2014-05-15 3 views
0

JFrame에서 대화 상자를 표시하고 있지만 대화 상자 외부를 클릭하면 대화 상자가 표시되지 않습니다. 대화 상자를 닫을 때까지 아무 것도 할 수 없도록되어 있습니다.다른 대화 상자가 열려있을 때 대화 상자로 돌아 가지 않음

이 내 코드입니다 :

첫 번째 대화에서 전화 대화 :이 JDialog의이라고

JProductStocking jps = JProductStocking.getProductStoking(JPanelTicket.this, oApp); 
jps.setVisible(true); 

그리고 :

public class JProductStocking extends javax.swing.JDialog implements BeanFactoryApp{ 
public JProductStocking(Component parent, boolean modal) { 
     //super(parent, modal); 
     initComponents(); 

    } 

public static JProductStocking getProductStoking(Component parent, AppView app) { 
     Window window = getWindow(parent); 

     JProductStocking myMsg; 
     if (window instanceof JFrame) { 
      myMsg = new JProductStocking((Frame) window, true); 
     } else { 
      myMsg = new JProductStocking((Dialog) window, true); 
     } 
     myMsg.init(app, parent); 
     myMsg.applyComponentOrientation(parent.getComponentOrientation()); 
     return myMsg; 
    } 

    private static Window getWindow(Component parent) { 
     if (parent == null) { 
      return new JFrame(); 
     } else if (parent instanceof JFrame || parent instanceof Dialog) { 
      return (Window) parent; 
     } else { 
      return getWindow(parent.getParent()); 
     } 
    } 

    public void init(AppView app, Component parent) { 
     oApp = app; 
     // m_dlSales = (DataLogicSales) app.getBean("com.openbravo.pos.forms.DataLogicSales"); 
     initComponents(); 
     ProductList = new ArrayList(); 
     this.setResizable(false); 
     setLocationRelativeTo(parent); 

    } 
} 

임 호출하지 JDialog를 잘? 뭐가 잘못 됐니?

+4

"JDialogs"생성자에 부모 'Window'를 전달하지 않으므로 차단할 부모를 알 수 없습니다. 생성자에서'// super (parent, modal);'주석을 작성 했으므로 눈에 띄어야합니다 ... – Holger

+0

@Holger @Holger 나는 그것을 잊을 수있는 방법을 모른다. 답변을 게시하면 받아 들일 것입니다. – user3480792

+0

@Holger 부모에게 제공하면 내가 잘못하지 않으면 대화 상자에 계속 표시됩니다. 사용자가 부모의 보이는 부분과 상호 작용하는 것을 막지는 않습니다. 이를 위해 대화 상자는 모달이어야합니다. – schmop

답변

2

당신은 JDialog의 생성자에 부모 Window없이 modal 플래그를 통과하지 않았다. 그 외에도 코드는 불필요합니다.

자바 6 이후로 의 생성자에 Window을 전달할 수 있으며, 따라서 null이 허용되므로 오류 방지입니다. 자바 6 Dialog.ModalityType 당신이 대화의 자녀 외에 다른 모든 응용 프로그램의 창을 차단 (APPLICATION_MODAL을)를 Dialog를 구성 할 수 있습니다 또는 차단하는 것을

public class JProductStocking extends javax.swing.JDialog 
    implements BeanFactoryApp { 

    public JProductStocking(Component parent, Dialog.ModalityType modality) { 
    super(SwingUtilities.windowForComponent(parent), modality); 
    initComponents(); 
    } 
// … 

참고 : 전체 코드처럼 보일 수 있습니다 SwingUtilities.windowForComponent 기존의 방법과 결합 대화 상자의 부모와 자녀 만 (DOCUMENT_MODAL). 단순한 modal 플래그보다 훨씬 더 많은 제어 기능을 제공합니다.

3

찾고있는 동작을 "모달"대화 상자라고합니다. 당신은 대화 생성자에 '사실'에 합격해야합니다 : 모덜리스의 기본 동작을 사용 그래서

public JProductStocking() { 
     super((Frame)null, true); //better to pass an actual Frame, Window or Dialog object as a parent 
     initComponents(); 

    } 
관련 문제