返回顶部

收藏

文本组件的打印 Printing...

更多
import java.awt.BorderLayout;
import java.text.MessageFormat;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;

public class JDK6TextComponentDemo {
  public static void main(String[] args) throws Exception {
    final JTextArea textArea = new JTextArea();
    textArea.setText(\"text\");
    JScrollPane jScrollPane = new JScrollPane(textArea);
    final MessageFormat header = new MessageFormat(\"My Header\");
    final MessageFormat footer = new MessageFormat(\"My Footer\");

    JPanel contentPane = new JPanel();
    contentPane.setLayout(new BorderLayout());
    contentPane.add(jScrollPane, BorderLayout.CENTER);

    JFrame frame = new JFrame();
    frame.setTitle(\"Text-component Printing Demo\");
    frame.setSize(400, 200);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    frame.setContentPane(contentPane);
    frame.setVisible(true);
    textArea.print(header, footer, true, null, null, true);

  }
}
//该片段来自于http://outofmemory.cn

标签:java,基础

收藏

0人收藏

支持

0

反对

0

发表评论