Java JDialog未调整大小

Java JDialog未调整大小,java,swing,jdialog,Java,Swing,Jdialog,当按下按钮时,我正在从JFrame打开JDialog,这是我的代码 private JDialog FindView; ~~> JDialog declaration. private void jMenuItem9ActionPerformed(java.awt.event.ActionEvent evt) { if (FindView == null) { JFrame mainFrame = myApp.getApplicati

当按下按钮时,我正在从JFrame打开JDialog,这是我的代码

   private JDialog FindView; ~~> JDialog declaration. 

   private void jMenuItem9ActionPerformed(java.awt.event.ActionEvent evt) {        
    if (FindView == null) {
        JFrame mainFrame = myApp.getApplication().getMainFrame();
        FindView = new MyAppFindView(mainFrame, true);
        FindView.setLocationRelativeTo(mainFrame);
    }
    myApp.getApplication().show(FindView);
}
但是JDialog总是以相同的大小打开。如何调整JDialog的大小

我检查了
表单大小策略
,它是
Generate pack()

这是我在FindView java文件中设置的大小

这是它打开时的大小

已解决

最后一行代码似乎是导致问题的原因。 将代码替换为
FindView.setVisible(true)解决了问题。

这应该可以做到:

JFrame mainFrame = myApp.getApplication().getMainFrame();
FindView = new MyAppFindView(mainFrame, true);
FindView.setLocationRelativeTo(mainFrame);
FindView.setPreferredSize(yourDimensions);

在放置或显示之前调用pack您的意思是希望JDialog以不同的大小打开,或者希望在打开后能够调整其大小?请尝试setresizeable(true)方法,可能会对您有所帮助。@AliAlamiri我只希望它以我设置的大小打开。@MadProgrammer我已经这样做了,它不会改变任何东西。