2012-04-01 49 views
2

您可以告訴我手動調整大小後調用JFrame/JDialog的方法嗎? (使用鼠標光標調整大小後,屏幕上可以看到框架)。我注意到我的JDialog不是有效的,儘管我在它上面調用了validate()revalidate(),但是在調整了一下後,我的框架就變得有效了。java調整大小的方法

+2

你的問題不明確。 「框架變得有效」是什麼意思?此外,如果您可以提供sscce – 2012-04-01 09:48:41

+1

正如我所看到的,您希望使您的JDialog有效,因爲它在調整大小後變得有效。看看這個線程關於驗證o JComponent:http://stackoverflow.com/questions/8362484/why-cant-i-validate-a-jcomponent – dexametason 2012-04-01 09:53:08

+0

成爲vaild意味着frame.isValid()返回true ...我不我認爲這很模糊。 – Teo 2012-04-01 10:10:14

回答

1

我認爲這是java.awt.event.ComponentListener

用於接收組件事件的偵聽器接口。當組件的大小,位置或可見性發生變化時,調用偵聽器對象中的相關方法 ,並將ComponentEvent傳遞給 它。

例如:

public class MyFrame extends JFrame implements ComponentListener { 

    @Override 
    public void componentResized(ComponentEvent e) { 
     // re compute? 
     repaint(); 
    } 
} 
+0

不應該是必要的...通常如果必要的話,重繪是自動處理的 – kleopatra 2012-04-01 14:08:12

0

有了這個代碼我能夠調整寬度,3代表的高度。

container.addControlListener(new ControlAdapter() { 
      @Override 
      public void controlResized(ControlEvent e) { 
       tableJobs.setBounds(20, 143,container.getBounds().width-40, container.getBounds().height-20); 
       tableMessages.setBounds(20, 143,container.getBounds().width-40, container.getBounds().height-20); 
       tableSplfs.setBounds(20, 143,container.getBounds().width-40, container.getBounds().height-20); 
      } 
     });