我试图制作一个模型浏览器,但是这一个错误不断出现,看起来很好的代码行。找不到添加(TextField)的合适方法?
import java.awt.Container;
import java.awt.Font;
import java.awt.Insets;
import javafx.scene.control.TextField;
import javax.swing.JEditorPane;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author PC
*/
public class Browser extends JFrame{
private TextField field = new TextField();
private JEditorPane display = new JEditorPane();
private JScrollPane scroller = new JScrollPane(display);
public static void main(String args[]){
Browser file = new Browser();
file.framelander();
}
public void framelander() {
setTitle("Browser");
setSize(1200, 800);
setResizable(false);
setVisible(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLayout(null);
setLocationRelativeTo(null);
addComponentsToFrame(getContentPane());
}
public void addComponentsToFrame(Container pane) {
Insets insets = getInsets();
pane.add(field);
pane.add(scroller);
Font font = new Font("Menlo", Font.PLAIN, 11);
field.setFont(font);
}
}
我得到的错误是在pane.add(field)与错误;
no suitable method found for add(TextField)
method Component.add(PopupMenu) is not applicable
(argument mismatch; TextField cannot be converted to PopupMenu)
method Container.add(Component) is not applicable
(argument mismatch; TextField cannot be converted to Component)
----
(Alt-Enter shows hints)
我也越来越“不兼容的类型:java.awt.Font中不能转换到javafx.scene.text.Font”在field.setFont(字体)的加粗部分;但我假设这是由于最初的错误。不过,我会在这里发布它。
任何和所有的帮助表示赞赏。提前致谢。
你的提示应该是“无法转换”以及包名......“javafx”和“awt”类不是完全兼容 –