Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Setting focus to a dialog button?

 
Serge Plourde
Ranch Hand
Posts: 140
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
try
buttonsPanel.yesButton.requestFocus();
------------------
 
Serge Plourde
Ranch Hand
Posts: 140
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 140
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So, I'm going to use a series of text labels in a GridLayout instead, to display multiple lines messages.
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic