2012-05-17 2 views
0

다른 모든 사람들과 반대되는 문제가있는 것 같습니다. JDialog에는 기본적으로 최소화 및 최대화 버튼이 있습니다. 최대화 버튼을 누르면 대화 상자가 최대화되지만 내용은 최대화됩니다. 거대한 대화 상자를 중심으로 동일한 크기로 유지됩니다. 가장자리를 잡고 대화 상자의 크기를 조정할 때도 마찬가지입니다.JDialog가 최대화시 재 레이아웃을 수행하지 않음

WindowStateListener를 추가하려고 시도했지만 결코 호출되지 않습니다. WindowListener를 추가했습니다. 이것은 Open/Close/Activate/Deactivate에서만 호출됩니다.

그래서 대화 상자의 내용을 대화 상자로 다시 가져 오거나 최대화 단추를 제거 할 수 있어야합니다. (최소화 버튼을 없애고 싶습니다.)

대화 상자의 컨트롤이 데이터 블록에서 동적으로 만들어 지므로 pack()을 수행하므로 함께 일할 초기 크기가 없습니다.

자, 여기 코드가 있습니다. 생성 된 모든 UI 패널도 GridBagLayouts에 있습니다.

public class FastAccessDialog extends JDialog implements BeanActionListener { 

private static final long serialVersionUID = 1L; 
private static final Cursor waitCursor  = new Cursor(Cursor.WAIT_CURSOR); 

private Cursor    oldCursor; 
private JPanel    cmdOutput; 
private JScrollPane   cmdOutputScroll; 

public FastAccessDialog(Frame owner, ObjectName bean, String methodName) throws InstanceNotFoundException, IntrospectionException, 
     ReflectionException, IOException { 
    super(owner); 
    setResizable(true); 
    setModal(false); 
    setTitle(BeanUtil.cleanUpCamelCase(methodName)); 

    boolean enabled = (UIHintUtil.isEnabled(bean) == EnableState.ENABLED); 

    // Find the BeanOperationInfo for that method. 
    MBeanInfo info = JMXConnectionSingleton.getInstance().getMBeanInfo(bean); 
    MBeanOperationInfo[] operations = info.getOperations(); 
    JComponent comp = null; 

    for (MBeanOperationInfo opInfo : operations) { 
     if (opInfo.getName().equals(methodName)) { 
      comp = OperationsManager.getInstance().createControls(bean, opInfo, this, true, enabled); 
      break; 
     } 
    } 

    if (comp == null) { 
     throw new IllegalArgumentException("Unknown method name: " + methodName); 
    } 

    Container cont = getContentPane(); 
    cont.setLayout(new GridBagLayout()); 
    GridBagConstraints gbc = new GridBagConstraints(); 
    gbc.anchor = GridBagConstraints.WEST; 
    gbc.gridx = 0; 
    gbc.gridy = 0; 
    gbc.fill = GridBagConstraints.HORIZONTAL; 
    gbc.insets = new Insets(4, 4, 4, 4); 
    cont.add(comp, gbc); 
    cont.validate(); 

    SwingUtilities.invokeLater(new Runnable() { 
     @Override 
     public void run() { 
      pack(); 
     } 
    }); 
    return; 
} 

... other methods invoked when an operation is performed ... 
... none of which are invoked before having the re-size problem ... 
} 
+2

일부 코드를 게시하여 진행 상황을 볼 수 있습니다. 이것은 일반적으로 올바른 LayoutManager를 사용하고 올바르게 구성하는 것과 관련이 있습니다. –

+3

더 나은 도움을 받으려면 [SSCCE] (http://sscce.org/)를 게시하십시오. –

답변

2
  1. JPanel.(re)validate();

  2. JPanel.repaint();

  3. JDialog.pack();

  4. SwingUtilities.invokeLater(new Runnable() { 
        @Override 
        public void run() { 
         JDialog.setVisible(true); 
        } 
    }); 
    
  5. 하지 확장 할 Top-Level Containers

  6. ContentPane를 사용하지 않는, 거기에 아무 이유 ... 경우에 다른 Java5

  7. 아무것도에서 JDialog.pack();JDialog.setVisible(true) 그; JDialog 인스턴스를 반환하는 void, method 또는 constructor의 마지막 코드 줄입니다.

관련 문제