How to put a placeholder JTextArea? I do not want to use a label , I think the placeholder is more elegant.
private void initialize() {
frame = new JFrame();
JTextField txtSfas = new JTextField();
TextPrompt txtSfas = new TextPrompt("First Name", txtSfas);
frame.getContentPane().add(txtSfas, BorderLayout.CENTER);
txtSfas.setColumns(2);
}
error:
TextPrompt cannot be resolved to a type
Looking for something like this? Text prompt
The SwingX library which can be used alongside normal Swing takes cares of this when you initialize a JXTextField and does the same for JXTextArea too.
JXTextField text = new JXTextField("Your Prompt Here");
text.setPrompt("New Prompt");
frame.add(text, BorderLayout.CENTER);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.