aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Setting focus to a dialog button? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Setting focus to a dialog button?" Watch "Setting focus to a dialog button?" New topic
Author

Setting focus to a dialog button?

Serge Plourde
Ranch Hand

Joined: Jun 23, 2000
Posts: 140
Hi,
I have a dialog window composed of two panels: a message panel with gridLayout(1,1), and a buttonsPanel with gridLayout(1,3).
When the parent application instantiate the dialog with the message, it packs the dialog, and set its visibility to true, then "yesButton.requestFocus()" but the focus is always in the message panel!
Could somebody provide any hint on this please?
Thanks.
Harish Kashyap
Ranch Hand

Joined: Jun 14, 2000
Posts: 118
try
buttonsPanel.yesButton.requestFocus();
------------------
Serge Plourde
Ranch Hand

Joined: Jun 23, 2000
Posts: 140
Thanks for trying to help, but that did not work.
I tried several other things without success that did not work
also.
I suspect that the TextArea object is keeping selfishly the
focus for itself!
Serge Plourde
Ranch Hand

Joined: Jun 23, 2000
Posts: 140
So, I'm going to use a series of text labels in a GridLayout instead, to display multiple lines messages.
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Hi
Can anybody help me to run the following code in frame. Same coding which i have done for applet executes very well.
The problem is with the requestFocus() which works fine with the applet but not with Frame.
Here follows the code for applet
//<applet code=KeyLDemo_applet width=500 height=500></applet>
import java.applet.Applet;
import java.awt.event.*;
import java.awt.*;
public class KeyLDemo_applet extends Applet implements KeyListener
{
TextField t1,t2;
public void init()
{
add(t1=new TextField(30));
add(t2=new TextField(10));
addKeyListener(this);
requestFocus();
}
public void keyPressed(KeyEvent ke)
{
t1.setText("key pressed");
int s=ke.getKeyCode();
char c=ke.getKeyChar();
t1.setText(c+" "+"key pressed");
String s1=ke.getKeyText(s);
switch(s)
{
case KeyEvent.VK_F1:
t1.setText(s+": key was pressed: "+s1);
break;
case KeyEvent.VK_UP:
t1.setText(s+": key was pressed: "+s1);
break;
case KeyEvent.VK_ESCAPE:
t1.setText(s+": key was pressed: "+s1);
break;
}
}
public void keyReleased(KeyEvent ke)
{t1.setText("key released");
}
public void keyTyped(KeyEvent ke)
{t2.setText("key typed");
}
}

Thanking you in advance
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Setting focus to a dialog button?