Pages

Determine when JFrame resized

Source code below will show you, how to determine when JFrame re sized.

***********************************************************************
COMPLETE SOURCE CODE FOR : DetermineWhenAJFrameIsResized.java
***********************************************************************


import javax.swing.JFrame;
import javax.swing.JOptionPane;

import java.awt.event.ComponentEvent;
import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentListener;

public class DetermineWhenAJFrameIsResized extends JFrame
{
//Create ComponentListener that will listen when JFrame is resizing
ComponentListener cl=new ComponentAdapter()
{
public void componentResized(ComponentEvent event)
{
JOptionPane.showMessageDialog(null,"New size with :\n"+"WIDTH : "+getSize().width+"\n"+"HEIGHT : "+getSize().height);
}
};

public DetermineWhenAJFrameIsResized()
{
super("TRY RESIZE ME");

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize(300,300);
setVisible(true);

//Add ComponentListener to JFrame
addComponentListener(cl);
}

public static void main(String[]args)
{
DetermineWhenAJFrameIsResized dwajfir=new DetermineWhenAJFrameIsResized();
}
}


***********************************************************************
JUST COMPILE AND EXECUTE IT
***********************************************************************
Related Posts Plugin for WordPress, Blogger...