Results 1 to 6 of 6

Thread: How To Know Whether A Component Resized or not?

  1. #1
    Join Date
    Nov 2009
    Posts
    117

    How To Know Whether A Component Resized or not?

    Hello, I want to know that is there any solution in java from which we are able to get to Know whether a component resized or not. If you are having any type of idea for achieving in java then please help me to achieve it. Thank you in advance.

  2. #2
    Join Date
    May 2008
    Posts
    2,389

    Re: How To Know Whether A Component Resized or not?

    For getting the solution on your problem you must need to make use of the component listener in java. The Component listener is a listener interface for receiving component events. A component is an object having a graphical representation that can be displayed on the screen and that can interact with the user. The class that is interested in processing a component event either implements this interface and all the methods it contains, or extends the abstract ComponentAdapter class overriding only the methods of interest. The listener object created from that class is then registered with a component using the component's addComponentListener method. When the component's size, location, or visibility changes, the relevant method in the listener object is invoked, and the ComponentEvent is passed to it. One or more component events are fired by a Component object just after the component is hidden, made visible, moved, or resized.

  3. #3
    Join Date
    Feb 2008
    Posts
    1,852

    Re: How To Know Whether A Component Resized or not?

    Hello, I think you must need to make use of the component listener for this purpose. If you simply use the methods below then you will able to get the solution for your problem.:

    • componentHidden(ComponentEvent)
    • componentMoved(ComponentEvent)
    • resizedCheck(ComponentEvent)
    • componentShown(ComponentEvent)

  4. #4
    Join Date
    Jan 2008
    Posts
    1,521

    Re: How To Know Whether A Component Resized or not?

    You can able to get the solution for your problem, by simply using the program below:
    Code:
    boolean resized = false; 
    paintComponent():
    {
        if ( resized == false ) create and paint Mandelbrot image;
        else super.paint();
    } 
    resized event start: resized = true;
    resized event end: resized  = false;

  5. #5
    Join Date
    Apr 2008
    Posts
    1,948

    Re: How To Know Whether A Component Resized or not?

    Hello, you can simply add the code below in your program and check whether your component is resized or not:
    Code:
    private Timer t1 = new Timer(1000, this);
    public void resizedCheck(ComponentEvent e)
    {
            p1.setShouldRecalculateImage(false);
            t1.start();
    }
     
    public void actionPerformed(ActionEvent e) 
    {
            p1.setShouldRecalculateImage(true);
            t1.stop();
            p1.repaint();
    }

  6. #6
    Join Date
    May 2008
    Posts
    2,389

    Re: How To Know Whether A Component Resized or not?

    Hey, if you simply use the code below then you will able to get the solution for your resizing is done or not:
    Code:
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JOptionPane;
    import java.awt.event.ComponentListener;
    import java.awt.event.ComponentAdapter;
    import java.awt.event.ComponentEvent;
    import java.awt.Component;
    
    public class compresizing
    {
     JFrame frame=new JFrame("Resizing"); 
     JButton b1=new JButton("MONSTER");
     
     public compresizing()
     {
      ComponentListener complistener=new ComponentAdapter()
      {
       public void componentResized(ComponentEvent evt)
       {
        Component comp=(Component)evt.getSource();
        int currentWidth=comp.getSize().width;
        int currentHeight=comp.getSize().height;
        JOptionPane.showMessageDialog(null,"Size changed to  : "+currentWidth+"\nMONSTER HEIGHT NOW : "+currentHeight,"Size",JOptionPane.INFORMATION_MESSAGE);
       }
      };  
      b1.addComponentListener(complistener);
      frame.add(b1);  
      frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      frame.setSize(400,100);
      frame.setVisible(true);
     } 
     public static void main(String[]args)
     {
      compresizing obj=new compresizing();
     }
    }

Similar Threads

  1. PDF File Can Be Resized?
    By GreatThinker in forum Operating Systems
    Replies: 6
    Last Post: 21-05-2010, 01:16 AM
  2. What is a EOL Component
    By Abbie in forum Monitor & Video Cards
    Replies: 6
    Last Post: 12-03-2010, 11:09 AM
  3. What are AdRotator Component in ASP?
    By Silent~Kid in forum Software Development
    Replies: 4
    Last Post: 10-02-2010, 01:37 AM
  4. Popwire WMV-9 Component 2.0
    By Cherrycooki in forum Operating Systems
    Replies: 2
    Last Post: 02-09-2009, 10:51 AM
  5. How to register a component in vb?
    By REEMAD in forum Software Development
    Replies: 3
    Last Post: 28-02-2009, 09:01 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,727,337,005.81045 seconds with 16 queries