Não consigo encontrar nenhuma informação sobre como pegar o "resize
"evento de um JInternalFrame
Eu realmente quero dizer interno quadro, Armação.
De fato, InternalFrameListener
não pega o "resize
"eventos.
Devo escrever eu mesmo usando o "JInternalFrame.addComponentListener(...)
"?
Respostas:
0 para resposta № 1Sim, você precisa usar addComponentListener()
para adicionar um ouvinte de redimensionamento ao JInternalFrame
.
A maneira mais compacta de fazer isso seria usar um ComponentAdapter
e substitua apenas o componentResized(final ComponentEvent e)
método:
jInternalFrame.addComponentListener(new ComponentAdapter() {
@Override
public void componentResized(final ComponentEvent e) {
super.componentResized(e);
System.out.println("Resizing");
}
});
Veja este exemplo simples e completo:
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);
}
}