Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Setting focus to a dialog button?

 
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.
 
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.
 
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
 
Beware the other head of science - it bites! Nibble on this message:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic