比如在一个JTextArea里面,我要设置"Courier New"的字体,不过setFont()之后,并不能显示中文(都变成方框了),如果setFont()为中文字体如宋体之后,英文也变成了难看的宋体格式,我的意思是,有没有办法像普通的winows文字编辑器那样,可以设置英文字体之余也能显示中文,PS:我用的os是英文的windows 2000

解决方案 »

  1.   

    那么在用哪个控件可实现?JEditPane/JTextPane? 请指教
      

  2.   

    请教楼上,我用JEditorPane后,发现确实可以用中文了,可是setfont为任何英文字体都不起作用了,都用的是宋体的英文。是不是还要做什么设置?
      

  3.   

    可用textpane,定义DefaultStyledDocument ,然后设置要插入字体的属性(颜色,字体,大小等),可随意显示了
      

  4.   


    import java.awt.*;
    import javax.swing.*;
    import javax.swing.text.*;public class StyledText {
      public static void main(String args[]) throws BadLocationException {
        JFrame jf = new JFrame("StyledText");
        jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        Container cp = jf.getContentPane();    JTextPane pane = new JTextPane();
        SimpleAttributeSet set = new SimpleAttributeSet();
        StyleConstants.setBold(set, true);    // Set the attributes before adding text
        pane.setCharacterAttributes(set, true);
        pane.setText("Eine ");    set = new SimpleAttributeSet();
        StyleConstants.setItalic(set, true);
        StyleConstants.setForeground(set, Color.red);
        StyleConstants.setBackground(set, Color.blue);    Document doc = pane.getStyledDocument();
        doc.insertString(doc.getLength(), "Kleine ", set);    set = new SimpleAttributeSet();
        StyleConstants.setFontSize(set, 24);    doc.insertString(doc.getLength(), "Nachtmusic", set);    JScrollPane scrollPane = new JScrollPane(pane);
        cp.add(scrollPane, BorderLayout.CENTER);    jf.setSize(400, 300);
        jf.setVisible(true);
      }
    }
      

  5.   

    DialogInput
    Dialog一个是等宽, 一个不是.
    Java默认的字体, 老兄, 忘本啊