accessing controls in a panel

R

rjl444

I have a frame that has a panel. in the panel is 3 controls. I need to
hide one of the controls when an event fires in the frame. I can hide
the panel easily, but how do I access a single control from the frame
to hide the control?
Thanks for any help,
Joe
 
Y

Yanick

I have a frame that has a panel. in the panel is 3 controls. I need to
hide one of the controls when an event fires in the frame. I can hide
the panel easily, but how do I access a single control from the frame
to hide the control?
Thanks for any help,
Joe

you assign a variable to that control, like :

JButton a = new JButton("Button A");

myFrame.getContentPane().add( a );

// ...

a.setVisible( false );

-Yanick
 
R

rjl444

it is Jframe, the controls are all Jbuttons. I would like to to do
setenable(false), but either enabled or visible, how do I get the
context of the Jbutton inside a panel.
Yanick- the Jbutton is inside a panel.
 
R

rjl444

it is Jframe, the controls are all Jbuttons. I would like to to do
setenable(false), but either enabled or visible, how do I get the
context of the Jbutton inside a panel.
Yanick- the Jbutton is inside a panel.
 
A

Andrew Thompson

it is Jframe,

JFrame? Please be precise.
..the controls are all Jbuttons.
Ditto.

I would like to to do
setenable(false)
Ditto.

, but either enabled or visible, how do I get the context

What 'context'? Are you asking how to get a reference to
the JButton? That would depend on your code[1] (or the code
your IDE wrote). Generally I declare UI controls as class
attributes, which makes it easy.

[1] This brings us to. Give us a compilable example of your
code (with just *2* JButtons) that shows what you are doing..
..of the Jbutton inside a panel.

But one way to remove a known component from a JPanel is..
<http://java.sun.com/j2se/1.5.0/docs/api/java/awt/Container.html#remove(java.awt.Component)>

You would get better value from a different group, for the moment.
<http://www.physci.org/codes/javafaq.jsp#cljh>

HTH
 
R

rjl444

i dont have access to the code right now, but to summerize:
1) I have Jframe class.
2) I have a method in thid class that builds a panel with JCommands.
let's say C1 and C2 they are called. I have them as private, i beleive
(perhaps I need to make thisthem gloabl) for the Jframe. I then add
them to a panel created in the method .
3) I then in the main class, I add this panel to the ContentPane.

I need to know how to reference C1 from a method in another independant
method in the JFrame class.
 
A

Andrew Thompson

i dont have access to the code right now,

That's me out of here, sorry. It is hard enough attempting to provide
technical assistance on a busy group without delving into apps. for
which you do not 'have access to the code'.

My best suggestion is that you compose a polite email to whoever
*has* access to the code, and ask them to provide a public method
specifically for removing/hiding the component of interest.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,189
Latest member
CryptoTaxSoftware

Latest Threads

Top