Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

focussing swing buttons using tab key  RSS feed

 
preethi Ayyappan
Ranch Hand
Posts: 518
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to get focus on my swing buttons immediately when i open the page without the help of mouse for the first time.my code is working. but sometimes it is not working.here is my code.please reply what is the fault there?

code:

public class AstMonitor extends JApplet implementsActionListener,FocusListener,Runnable {

boolean keepTrying = true;
Thread astThread;

JButton sale = new JButton("12 Sale ");
public void init() {

resize(150,475);



setForeground( java.awt.Color.black );

setBackground( new java.awt.Color(237,237,237) );



setFont( new Font("Tacoma", Font.PLAIN, 12) );

GridLayout gl;
getContentPane().setLayout(new GridLayout(10,3));
nosale.setActionCommand("nosale");

nosale.addActionListener(this);

this.getContentPane().add(nosale);

nosale.setMnemonic('e');

nosale.setBackground(Color.pink);
astThread = new Thread(this);

astThread.start();



}
public void focusGained(FocusEvent fe)
{
if(fe.getSource()==nosale)

System.out.println(nosale.getLabel()+"gained");
if(fe.isTemporary())

System.out.println("Temporary Focus");

}
public void focusLost(FocusEvent fe)

{
if(fe.getSource()==nosale)

System.out.println(nosale.getLabel()+"lost");
}

Thanks.
 
preethi Ayyappan
Ranch Hand
Posts: 518
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Any idea about the above code.pls reply.anyone help me
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!