JWindow focus problem

Hi,I need help. I have JWindow object with two textboxes in it. When JWindow activated I make one of the textboxes focusable and type some text there. After this, I click on the second textbox with mouse, but it doesn't get focus !!?Can sombody help me?
[296 byte] By [aljoha] at [2007-9-26 3:13:36]
# 1
Could u post a piece of code.....
sasivarnan at 2007-6-29 11:23:05 > top of Java-index,Archived Forums,Swing...
# 2

Did you disable focus on that TextField object somewhere, through a setFocusEnabled(false)?

Another possibility: If your Texfield is grayed out, you must have disabled it somewhere, through a setEnabled(false) call.

Post some code if the problem remains. This type of problem has a deceptively simple solution ;-)

Regards,

Eric

Eric.Vautier at 2007-6-29 11:23:05 > top of Java-index,Archived Forums,Swing...
# 3
Could also be that the method forcing the focus on the first textfield gets called regularly (like in the paint method, or in your mouse click-handler).
Eric.Vautier at 2007-6-29 11:23:05 > top of Java-index,Archived Forums,Swing...
# 4

Some code :

public class SplashWindow extends JWindow {

JPanel jPanel1 = new JPanel();

XYLayout xYLayout1 = new XYLayout();

JTextField jTextField2 = new JTextField();

JTextField jTextField1 = new JTextField();

JButton jButton1 = new JButton();

Border border1;

public SplashWindow() {

try {

jbInit();

}

catch(Exception e) {

e.printStackTrace();

}

}

private void jbInit() throws Exception {

border1 = BorderFactory.createCompoundBorder(BorderFactory.createBevelBorder(BevelBorder.RAISED,Color.white,Color.white,new Color(134, 134, 134),new Color(93, 93, 93)),BorderFactory.createEmptyBorder(5,5,4,4));

jPanel1.setLayout(xYLayout1);

jTextField2.setText("jTextField2");

jTextField1.setNextFocusableComponent(jTextField2);

jTextField1.setText("jTextField1");

jButton1.setText("jButton1");

jPanel1.setBorder(BorderFactory.createRaisedBevelBorder());

this.getContentPane().add(jPanel1, BorderLayout.CENTER);

jPanel1.add(jButton1, new XYConstraints(126, 68, -1, -1));

jPanel1.add(jTextField1, new XYConstraints(59, 102, -1, -1));

jPanel1.add(jTextField2, new XYConstraints(198, 106, -1, -1));

}

}

............................................

SplashWindow frame = new SplashWindow();

frame.setSize(new Dimension(400,200));

frame.setVisible(true);

frame.jTextField2.setRequestFocusEnabled(true);

frame.jTextField1.setRequestFocusEnabled(true);

frame.jTextField1.setNextFocusableComponent(frame.jTextField2);

frame.jTextField1.requestFocus();

and it doesn't work as I need :/

aljoha at 2007-6-29 11:23:05 > top of Java-index,Archived Forums,Swing...
# 5

Do the following things and let me know...

*setVisible(true) must be the last statement in ur constructor!

*Remove these lines completlyjTextField1.setNextFocusableComponent(jTextField2);

frame.jTextField2.setRequestFocusEnabled(true);

frame.jTextField1.setRequestFocusEnabled(true);

frame.jTextField1.setNextFocusableComponent(frame.jTextField2);

frame.jTextField1.requestFocus();

sasivarnan at 2007-6-29 11:23:05 > top of Java-index,Archived Forums,Swing...
# 6
You are setting the nextFocusableComponent of jTextField2 to jTextField2 - itself! so focus never leaves.
alsues at 2007-6-29 11:23:05 > top of Java-index,Archived Forums,Swing...
# 7
1. Make sure jTextField1.requestFocus() is only called once.2. If it is, there may be something awry in your custom layout manager (XYLayout). Have you tried using setLocation() and setSize() on the components themselves, without the custom layout?
Eric.Vautier at 2007-6-29 11:23:05 > top of Java-index,Archived Forums,Swing...