• Post Reply Bookmark Topic Watch Topic
  • New Topic

How do you disable a button within another class

 
bobby, morkos
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have this layout:
Mainpanel contains:
MainPnl
btnPnl
From MainPnl how do you get a button from btnPnl and button.setEnable(false);
I'm having problems referring to the button
 
Rob Ross
Bartender
Posts: 2205
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You could write a getter method in your button panel that returns a reference to the button.
in BtnPanel, I assume you have some instance variable to keep track of your button like
JButton theButton;
just write a method to return this
JButton getButton(){ return theButton; }
And call getButton() from your main panel.

Rob
 
bobby, morkos
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's what I did and I get a NullPointerException. I did what you told me, but I'm having difficulties. Please help?
Originally posted by Rob Ross:
You could write a getter method in your button panel that returns a reference to the button.
in BtnPanel, I assume you have some instance variable to keep track of your button like
JButton theButton;
just write a method to return this
JButton getButton(){ return theButton; }
And call getButton() from your main panel.

Rob

[ February 06, 2002: Message edited by: bobby, morkos ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!