Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

JButton in swing,,,how to set it immovalble? 3

Status
Not open for further replies.

qb828

Programmer
Sep 27, 2000
98
US
hello!
how are you?
i have two rows of JButtons.and i want to set top row JButtons not clickable a while i let bottom row Jbuttons to be clickable and vice versa.
is there a such method you can set JButtons to be immobile?

thanks a lot for your help.

Q
 
Yes.

[tt]method -> .setEnabled( boolean );[/tt]

I would recommend going to Sun's website for this type of question. Just bookmark this site and go there when you have a question about a certain object's methods and such.

I hope this helped! ;-)
- Casey Winans
 
Hi,

Casey is right. It will help you or anyone doing Java programs a lot if you take a look at the Java API. Better still if you can download the whole API so that everytime you need to know the available methods of the Classes in JDK, you wouldn't have to log on to the net.

I have coded an example for you as well in case you didn't get what Casey was trying to say.

//Example:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class ButtonTest extends JFrame implements ActionListener
{
JButton top, bottom;
public ButtonTest()
{
setSize(100,100);
getContentPane().setLayout(null);
top = new JButton("Top");
top.setBounds(new Rectangle(10,10,75,25));
top.addActionListener(this);
getContentPane().add(top,null);

bottom = new JButton("Bottom");
bottom.setBounds(new Rectangle(10,40,75,25));
bottom.addActionListener(this);
getContentPane().add(bottom,null);
}

public void actionPerformed(ActionEvent e)
{
String action = e.getActionCommand();
if (action.equals("Top"))
{
top.setEnabled(false);
bottom.setEnabled(true);
}
else if (action.equals("Bottom"))
{
top.setEnabled(true);
bottom.setEnabled(false);
}
}
public static void main(String[] args)
{
new ButtonTest().show();
}
}

Regards,
Leon If you need additional help, you can email to me at zaoliang@hotmail.com I don't guaranty that I will be able to solve your problems but I will try my best :)
 
Yes ,
Mr qb828, zaoling is right the basic and important part of it is to enable the button.

//business logic...........
top.setEnabled(true);
bottom.setEnabled(false);

//business logic...........
top.setEnabled(false);
bottom.setEnabled(true);

 
thanks casey, leon & srikandula..
i have two books, java2 in 21 days & how to program java by deitel. i didn't find anything about it. but i remembered
i heard about it. that was why i posted here(last stop, hoping someone might explain to me).
and this site is very helpful that there are a lot of nice people who takes time to answer and help. my friend told me this site and i have been using this site since then.
yes, i do have installed java API on my home computer.
i didn't see .setEnable under Swing, JButton, under method summary.
i guess i had been looking a wrong place.
again thanks millions, guys.

Q
 
You need to remember, JButton has all the JButton methods AND all the Button methods. That's the beauty and confusion of inheritance!

Rose/Miros
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top