0

I have one JFrame and calling a JDialog from that frame while initializing. In the dialog have a JButton, when clicking on the button a new JWindow opens.

Can I fix the position of window in the main frame? How to access the parent container (JFrame extended) from JWindow extended class?

4

1 に答える 1

2

SwingUtilities.getWindowAncestorを使用します。クラス内にある場合JWindowは として参照しthis、そうでない場合は単に object を内部に配置します。

JFrame topFrame = (JFrame) SwingUtilities.getWindowAncestor(this);

JFrame topFrame = (JFrame) SwingUtilities.getWindowAncestor(myJWindow);
于 2015-05-08T11:31:32.663 に答える