I have a JPanel cPanel
, and a TextField resultField
imported from JDK 8's javafx.scene.control.TextField
. Now I want to cPanel.add(resultField,BorderLayout.NORTH)
, Eclipse give me an error:
The method add(String, Component) in the type Container is not applicable for the arguments (TextField, String)
How do I add resultField
to cPanel
properly?
but JTextField doesn't support prompt text
You can use the Text Prompt class.
I allows you to specify a prompt that is displayed when the text field is empty. As soon as you type text the prompt is removed.
The prompt is actually a JLabel so you can customize the font, forground etc..:
JTextField tf7 = new JTextField(10);
TextPrompt tp7 = new TextPrompt("First Name", tf7);
tp7.setForeground( Color.RED );
You can Download swingx-core-1.6.2.jar and use it to make swing Text Fields Prompt text.
PromptSupport.setPrompt("User ID", userNameField);
PromptSupport.setFontStyle(Font.BOLD, userNameField);
PromptSupport.setForeground(Color.BLACK, userNameField);
PromptSupport.setFocusBehavior(PromptSupport.FocusBehavior.HIDE_PROMPT,
userNameField);
Download it from here : http://www.java2s.com/Code/JarDownload/swingx/swingx-core-1.6.2.jar.zip
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.