aspose file tools
The moose likes Swing / AWT / SWT and the fly likes focussing swing buttons using tab key Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Reply Bookmark "focussing swing buttons using tab key" Watch "focussing swing buttons using tab key" New topic
Author

focussing swing buttons using tab key

preethi Ayyappan
Ranch Hand

Joined: Oct 04, 2007
Posts: 518
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

Joined: Oct 04, 2007
Posts: 518
Any idea about the above code.pls reply.anyone help me
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: focussing swing buttons using tab key
 
Similar Threads
Tooltips
how to get focus on a swing button
JComboBox and FocusListener
setMnemonic
setMnemonic