0

Python をサポートする必要がある Swing JEditorPane を埋め込もうとしている SWT コンポジットがあります。これにはjSyntaxPaneを使用しています。完全な .py ファイルを読み取ってエディターに表示できます。ただし、構文/色の強調表示はエディターに表示されません。

以下はコードです:

public static void main(String args[]) {
    final Display display = new Display();
    final Shell shell = new Shell(display);
    shell.setText("Editor With Python Supprot");
    shell.setLayout(new FillLayout());

    Composite rtfComposite = new Composite(shell, SWT.EMBEDDED);

    java.awt.Frame frame = SWT_AWT.new_Frame(rtfComposite);
    java.awt.Panel panel = new java.awt.Panel(new java.awt.FlowLayout());
    frame.add(panel);

    //DefaultSyntaxKit.initKit();
    //PythonSyntaxKit.initKit();

    StyledEditorKit sek = new StyledEditorKit();
    //PythonSyntaxKit psk = new PythonSyntaxKit();
    //RTFEditorKit rtf = new RTFEditorKit();        

    JEditorPane editor = new JEditorPane();
    JScrollPane scrPane = new JScrollPane(editor);
    editor.setEditorKit(sek);
    //editor.setContentType("text/python");     
    editor.setBackground(Color.white);

    JScrollPane scroller = new JScrollPane();
    scroller.getViewport().add(editor);
    panel.add(scroller);

    try {

        FileInputStream fi = new FileInputStream("C:\\STEP_SAMPLE.py");
        sek.read(fi, editor.getDocument(), 0);

    } catch (FileNotFoundException e) {
        System.out.println("File not found");
    } catch (IOException e) {
        System.out.println("I/O error");
    } catch (BadLocationException e) {
    }

    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}

DefaultSyntaxKit または PythonSyntaxKit を初期化しようとすると、UI に何も表示されません。「editor.setContentType("text/python")」も実行しようとしましたが、うまくいきませんでした。

親切に助けてください。ありがとう。

4

1 に答える 1