Hello people:
I am trying to create a ComponentListener method that will resize some components when the window is resized. I have tried the following code, only to find out that it didnt work:

import java.awt.event.*;
import java.awt.*;

public class PowerEvent {
    PowerMath gui;

    PowerEvent(PowerMath in) {
        gui = in;
        gui.addComponentListener(new ComponentAdapter() {

            public void componentHidden(ComponentEvent e) {
            }

            public void componentMoved(ComponentEvent e) {
            }

            public void componentResized(ComponentEvent e) {
                gui.output.setPreferredSize( new Dimension( gui.getWidth()-30, gui.getHeight()-80 ));
            }

            public void componentShown(ComponentEvent e) {
            }
        }
        );
    }

    public void actionPerformed(ActionEvent evt) {
    }

}

I would appreciate it if anyone could tell me how to fix my problem of the code not working or mabye suggest another method?

Thanks in advance,
mintsmike

Is your method being called when you resize the component? Just setting the preferred size doesn't necessarily mean that the component will be resized. Depending on what layout manager you are using you may need to set the minimum, maximum and preferred sizes to get the result you want.

From now on, i will use the netBeans ide Design Editor to create my GUIs. It solved my problem this time, so whats to say it wont in future times to come

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.