CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Jun 1999
    Posts
    25

    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.





  2. #2
    Join Date
    Jun 1999
    Location
    Atlanta, GA
    Posts
    57

    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

  3. #3
    Join Date
    Jun 1999
    Posts
    25

    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?


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured