我試圖製作一個模型瀏覽器,但是這一個錯誤不斷出現,看起來很好的代碼行。找不到添加(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」類不是完全兼容 –