我有一个 JPanel cPanel
和一个从 JDK 8 的 javafx.scene.control.TextField
导入的 TextField resultField
。
现在我想要cPanel.add(resultField,BorderLayout.NORTH)
,Eclipse给我一个错误:
The method add(String, Component) in the type Container is not applicable for the arguments (TextField, String)
如何正确地将 resultField
添加到 cPanel
?
最佳答案
but JTextField doesn't support prompt text
您可以使用Text Prompt类。
I 允许您指定文本字段为空时显示的提示。一旦您输入文本,提示就会被删除。
提示实际上是一个 JLabel,因此您可以自定义字体、前景等......:
JTextField tf7 = new JTextField(10);
TextPrompt tp7 = new TextPrompt("First Name", tf7);
tp7.setForeground( Color.RED );
关于java - 将 JavaFX TextField 添加到 JPanel,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33704312/