展开全部
package com;
import java.awt.FlowLayout;
import java.awt.event.FocusAdapter;
import java.awt.event.FocusEvent;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JTextField;
public class Kyo extends JFrame
{
public Kyo()
{
setSize(100,100);
setLayout(new FlowLayout());
final JTextField textField = new JTextField(11);
textField.addFocusListener(new FocusAdapter()
{
@Override
public void focusGained(FocusEvent e)
{
textField.setText("");
}
@Override
public void focusLost(FocusEvent e)
{
textField.setText("输入内容");
}
});
add(textField);
add(new JButton("dd"));
pack();
setLocationRelativeTo(null);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
}
public static void main(String[] args)
{
new Kyo();
}
}
追问
请问怎样才不会默认选中文本框?还有怎样使 textField.setText("输入内容")里面的文字模糊一点?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询