Disabling components in a container when the container is disabled.
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.
Re: Disabling components in a container when the container is disabled.
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
Re: Disabling components in a container when the container is disabled.
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?