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,

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

This question has already been answered. Start a new discussion instead.