How to Make the TextField Focus?
Page 1 of 1
How to Make the TextField Focus?
#1
Posted 02 May 2008 - 03:08 PM
Just say, My TextField now appear word "Hello World".
JTextField txt1 = new JTextField("Hello World");
It in gray color,
txt1.setForeground(Color.GRAY);
When the user click on the JTextField The word change to none. You can only see the curser blinking....
How to do this?
Thanks.
JTextField txt1 = new JTextField("Hello World");
It in gray color,
txt1.setForeground(Color.GRAY);
When the user click on the JTextField The word change to none. You can only see the curser blinking....
How to do this?
Thanks.
#2
Posted 02 May 2008 - 03:19 PM
fsloke, on 2 May, 2008 - 04:08 PM, said:
Just say, My TextField now appear word "Hello World".
JTextField txt1 = new JTextField("Hello World");
It in gray color,
txt1.setForeground(Color.GRAY);
When the user click on the JTextField The word change to none. You can only see the curser blinking....
How to do this?
Thanks.
JTextField txt1 = new JTextField("Hello World");
It in gray color,
txt1.setForeground(Color.GRAY);
When the user click on the JTextField The word change to none. You can only see the curser blinking....
How to do this?
Thanks.
Focus/not focus only changes background color.
If it is gray and set foreground color to gray... sure you wont see the text anymore the foreground and background colors are the same.
Don't understand your question.... "The word change to none"
"How to do this?" How to do what ?
#4
Posted 02 May 2008 - 04:14 PM
import java.awt.*;
import javax.swing.*;
public class TField extends JFrame {
TField() {
super("TextField test");
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
setSize(300, 150);
JTextField t = new JTextField("Hello World");
t.setForeground(Color.GRAY);
add(t, BorderLayout.CENTER);
// just to have 2 elements who can have focus
add(new JButton("OK"), BorderLayout.SOUTH);
setVisible(true);
}
public static void main(String[] args) {
new TField();
}
}
TextField appears with ForegroundColor gray
When we click on it
Hello World stays there
the cursor appears in the JTextField
#6
Posted 03 May 2008 - 07:18 AM
fsloke, on 3 May, 2008 - 03:38 AM, said:
Only have one component...
No need the Button appear there....
I think have to implements MouseListener.....
Remember only one Component ie ONE TEXTFIELD
Thank you
No need the Button appear there....
I think have to implements MouseListener.....
Remember only one Component ie ONE TEXTFIELD
Thank you
If also works without the button. I just added the button so I can change to see if what happens when the focus changes. Could not reproduce the behaviour you are experiencing. May be you will have to post your code.
#7
Posted 03 May 2008 - 05:48 PM
Now it still researching for solution yet.
My coding a bit similar as yours.
Now I thinking how the Frame can detect which components are actived?
Do you know how?
Just say, the frame has JTEXTFIELD, JBUTTON, CHECKBOX....
When user click or tab either component, we will see the active message by using System.out.println("MSG");,
Example "USer click on JButton", "USer Click on CHeckBOX1", "USer Click on JTExtField".
Last time I got saw this tutorial. But now I have to retrieve it back....At that time I not save the URL down.
Thanks.....
My coding a bit similar as yours.
Now I thinking how the Frame can detect which components are actived?
Do you know how?
Just say, the frame has JTEXTFIELD, JBUTTON, CHECKBOX....
When user click or tab either component, we will see the active message by using System.out.println("MSG");,
Example "USer click on JButton", "USer Click on CHeckBOX1", "USer Click on JTExtField".
Last time I got saw this tutorial. But now I have to retrieve it back....At that time I not save the URL down.
Thanks.....
Page 1 of 1

Start a new topic
Add Reply




MultiQuote
| 


