Click to See Complete Forum and Search --> : Disabling components in a container when the container is disabled.


beginner
September 29th, 1999, 08:03 AM
Sample code in AWT:
-------------------

import java.awt.*;

class Try {
public static void main(String[] args)
{
Frame frame = new Frame();
Panel panel = new Panel();
Button button = new Button("Click");
panel.add(button);
panel.setEnabled(false);
frame.add(panel);
frame.setVisible(true);
frame.pack();
}
}

By executing the above code the button in the panel gets disabled.

Sample code in Swing:
---------------------
import javax.swing.*;

class Try {
public static void main(String[] args)
{
JFrame frame = new JFrame();
JPanel panel = new JPanel();
JButton button = new JButton("Click");
panel.add(button);
panel.setEnabled(false);
frame.getContentPane().add(panel);
frame.setVisible(true);
frame.pack();
}
}

By executing the above code the button in the panel does not get disabled.

meherss
September 30th, 1999, 04:37 PM
Enable or disable is to a particular component not to all the the components with in that.
You have to disable/enable the specific components rather than panel.


Meher

beginner
October 1st, 1999, 12:52 AM
Ok, Meher, I did disable a particular component, say, a button in a panel. The button got greyed. I had registered the button as a MouseListener. So when I clicked on the disabled button the mouse event got triggered. How is that happening?