Hi Folks,
I have JPanel component with bunch of JLabels, JButtons, JTextField etc
in it.
I was wondering if there is any way I could disable(and enable also) all
the components in my JPanel instead of picking every component
individually and doing setEnabled(false) on it ?
Best regards,
VK
|
|
0
|
|
|
|
Reply
|
Vk
|
3/7/2005 10:02:56 PM |
|
In article <d0iiti$dhq$1@news1nwk.SFbay.Sun.COM>,
Vk <trulytrojan@netscape.net> wrote:
> Hi Folks,
>
> I have JPanel component with bunch of JLabels, JButtons, JTextField etc
> in it.
>
> I was wondering if there is any way I could disable(and enable also) all
> the components in my JPanel instead of picking every component
> individually and doing setEnabled(false) on it ?
>
> Best regards,
> VK
If you refer to the API docs for JComponent's setEnabled method, it
specifically states that disabling a component does not disable its
children. So I would suggest that your best best is to use a custom
JPanel class, even if only to override the setEnabled method so that you
enable and disable child components as you wish.
= Steve =
--
Steve W. Jackson
Montgomery, Alabama
|
|
0
|
|
|
|
Reply
|
Steve
|
3/7/2005 10:13:23 PM
|
|
Steve W. Jackson wrote:
> In article <d0iiti$dhq$1@news1nwk.SFbay.Sun.COM>,
> Vk <trulytrojan@netscape.net> wrote:
>
>
>>Hi Folks,
>>
>>I have JPanel component with bunch of JLabels, JButtons, JTextField etc
>>in it.
>>
>>I was wondering if there is any way I could disable(and enable also) all
>>the components in my JPanel instead of picking every component
>>individually and doing setEnabled(false) on it ?
>>
>>Best regards,
>>VK
>
>
> If you refer to the API docs for JComponent's setEnabled method, it
> specifically states that disabling a component does not disable its
> children. So I would suggest that your best best is to use a custom
> JPanel class, even if only to override the setEnabled method so that you
> enable and disable child components as you wish.
>
> = Steve =
Right.
Override setEnabled() to resurce into all children and child containers
calling setEnabled() on each one.
Rogan
--
Rogan Dawes
*ALL* messages to discard@dawes.za.net will be dropped, and added
to my blacklist. Please respond to "nntp AT dawes DOT za DOT net"
|
|
0
|
|
|
|
Reply
|
Rogan
|
3/8/2005 8:05:10 AM
|
|
first crate an array of type Component type for example
final Component compo[]= new Component[] {
jTextField1, jCheckBox1 }.
then
for (int i = 0; i < components.length; i++)
{
if(compo[i] instanceof JCheckBox)
(JCheckBox)( compo[i])).setEnabled(false);
else if ( compo[i] instanceof JTextField)
(JTextField)( compo[i])).setEnabled(false);
}
This is one alternative there may be other efficient alternative
for example find if there is a way for getting all the components of a
panel in an array of strings and using the same for loop as above check
the type of components using "instance of" and apply setEnabled(false);
I hope there must be a way to get the list of all the components of a
container
praveen
--
Message posted via http://www.javakb.com
|
|
0
|
|
|
|
Reply
|
Praveen
|
3/8/2005 8:55:04 AM
|
|
Praveen homkar via JavaKB.com wrote:
> first crate an array of type Component type for example
>
> final Component compo[]= new Component[] {
>
> jTextField1, jCheckBox1 }.
>
> then
>
> for (int i = 0; i < components.length; i++)
> {
> if(compo[i] instanceof JCheckBox)
> (JCheckBox)( compo[i])).setEnabled(false);
> else if ( compo[i] instanceof JTextField)
> (JTextField)( compo[i])).setEnabled(false);
> }
>
> This is one alternative there may be other efficient alternative
>
> for example find if there is a way for getting all the components of a
> panel in an array of strings and using the same for loop as above check
> the type of components using "instance of" and apply setEnabled(false);
>
> I hope there must be a way to get the list of all the components of a
> container
>
> praveen
>
Too complicated ;-)
overriding setEnabled in JPanel:
public void setEnabled(boolean enabled) {
super.setEnabled(enabled);
setChildrenEnabled(this, enabled);
}
private void setChildrenEnabled(Container container, boolean enabled) {
for (int i=0; i<container.getComponentCount(); i++) {
Component comp = container.getComponent(i);
comp.setEnabled(enabled);
if (comp instanceof Container)
setChildrenEnabled((Container) comp, enabled);
}
}
Rogan
--
Rogan Dawes
*ALL* messages to discard@dawes.za.net will be dropped, and added
to my blacklist. Please respond to "nntp AT dawes DOT za DOT net"
|
|
0
|
|
|
|
Reply
|
Rogan
|
3/8/2005 10:16:41 AM
|
|
|
4 Replies
504 Views
(page loaded in 0.071 seconds)
Similiar Articles: How to DISABLE group of Components in JPanel - comp.lang.java.gui ...Hi Folks, I have JPanel component with bunch of JLabels, JButtons, JTextField etc in it. I was wondering if there is any way I could disable(and en... Disabling Gui Components - comp.soft-sys.matlabHow to DISABLE group of Components in JPanel - comp.lang.java.gui ... JTextField - how to disable selecting text in this component ... How to DISABLE group of Components ... How to prevent JPanel losing focus ? Follow - Computer GroupHow to DISABLE group of Components in JPanel - comp.lang.java.gui ... How to prevent JPanel losing focus ? - comp.lang.java.gui ... How to DISABLE group of Components in ... Scaling/Resizing 2D graphics in JPanel Follow - Computer GroupDisabling Gui Components - comp.soft-sys.matlab How to DISABLE group of Components in JPanel - comp.lang.java.gui ... Scaling/Resizing 2D graphics in JPanel - comp.lang ... How to clear JPanel? - comp.lang.java.guiDisabling Gui Components - comp.soft-sys.matlab How to clear JPanel? - comp.lang.java.gui How to DISABLE group of Components in JPanel - comp.lang.java.gui ... How to send mouse event to another component? Follow - Computer GroupHi, I have built a JPanel with lots of other ... Groups | Stream ... int x, int y) // deprecated of class Component. Class JPanel has ... Replacing an existing jPanel with a new jPanel - comp.lang.java ...... Post Question | Groups ... On one form, I have an existing > JPanel that contains no other components. JFrame prevent resize - comp.lang.java.guiScaling/Resizing 2D graphics in JPanel - comp.lang ... java.gui When I press and drag a ... Swing component ... comp.os.ms-windows.programmer.win32 ... How to DISABLE group ... JTextField in a JMenuItem - comp.lang.java.gui... Groups | Stream ... JMenuItem { JPanel pnlmain = new JPanel ... JTextField - how to disable selecting text in this component ... How to add a custom JPanel into a JTabbedPane with NetBeans 5 ...... Post Question | Groups ... Also, I've a custom UserPanel class (extends JPanel) which I want to put into a tab of the JTabbedPane component in ... How to DISABLE group of Components in JPanel - comp.lang.java.gui ...Hi Folks, I have JPanel component with bunch of JLabels, JButtons, JTextField etc in it. I was wondering if there is any way I could disable(and en... Disabling a JPanel and all it's components (Swing / AWT / SWT ...Disabling a JPanel and all it's components; Tanveer Rameez Ranch Hand Joined: Dec ... any way by which I can disable/enable the mypanel to disable/enable all the components ... 7/24/2012 11:25:43 AM
|