This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Setting focus to a dialog button?

 
Serge Plourde
Ranch Hand
Posts: 140
  • 0
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
try
buttonsPanel.yesButton.requestFocus();
------------------
 
Serge Plourde
Ranch Hand
Posts: 140
  • 0
  • 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
  • 0
  • 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
  • 0
  • 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
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic