2016-07-12 5 views
-1

JInternalFrame의 "resize"이벤트를 잡는 방법에 대한 정보는 찾을 수 없습니다. 실제로는 내부의 프레임을 의미합니다.자바 내부 프레임 크기 조정 이벤트 리스너?

사실 InternalFrameListener은 "resize"이벤트를 포착하지 않습니다.

"JInternalFrame.addComponentListener(...)"을 사용하여 직접 작성해야합니까?

답변

0

예, addComponentListener()을 사용하여 JInternalFrame에 크기 조절 수신기를 추가해야합니다.

ComponentAdapter를 사용 만 componentResized(final ComponentEvent e) 방법 오버라이드 (override)하는 것이 작업을 수행하는 가장 콤팩트 한 방법 다음에 대한

import javax.swing.*; 
import java.awt.*; 
import java.awt.event.ComponentAdapter; 
import java.awt.event.ComponentEvent; 

public class Example { 

    public static void main(String[] args) { 
     SwingUtilities.invokeLater(Example::createFrame); 
    } 

    private static void createFrame() { 

     JFrame jFrame = new JFrame(); 
     jFrame.setLocationRelativeTo(null); 

     JDesktopPane jDesktopPane = new JDesktopPane(); 
     jDesktopPane.setPreferredSize(new Dimension(600, 600)); 

     JInternalFrame jInternalFrame = new JInternalFrame(); 
     jInternalFrame.setBackground(Color.BLUE); 
     jInternalFrame.setResizable(true); 
     jInternalFrame.setSize(new Dimension(300, 300)); 
     jInternalFrame.setLocation(100, 100); 
     jInternalFrame.setVisible(true); 

     jInternalFrame.addComponentListener(new ComponentAdapter() { 
      @Override 
      public void componentResized(final ComponentEvent e) { 
       super.componentResized(e); 
       System.out.println("Resizing"); 
      } 
     }); 

     jDesktopPane.add(jInternalFrame); 

     jFrame.setContentPane(jDesktopPane); 
     jFrame.pack(); 
     jFrame.setVisible(true); 
    } 
} 
+0

감사 :

jInternalFrame.addComponentListener(new ComponentAdapter() { @Override public void componentResized(final ComponentEvent e) { super.componentResized(e); System.out.println("Resizing"); } }); 

이 단순하고 완전한 예를 살펴를 예. 그러나 이제는 클래스가 jInternalFrame을 확장하는 또 다른 클래스를 확장하므로 다른 문제가 발생합니다. – Titi

+0

@ 티티 왜 그렇게 문제가 있습니까? – explv

+0

당신의 힙을 가져 주셔서 감사합니다. 당신 말이 맞아 ... 문제 없어. 첫째, 나는 내 클래스가 이미 jInternalFrame을 확장 한 이후로 ComponentAdapter를 확장해야한다고 생각했다. ComponentListener를 구현할 수있는 또 다른 방법 인 ComponentListener를 구현할 수 있다는 것도 발견했다. – Titi