javax.swing.JTextPane#setDocument ( )源码实例Demo

下面列出了javax.swing.JTextPane#setDocument ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: DominionSim   文件: DomGameFrame.java
private JPanel getLogPanel() {
	JPanel theLogPanel = new JPanel();
	theLogPanel.setLayout(new BorderLayout());
	myLogPane = new JTextPane();
	myLogPane.setPreferredSize(new Dimension(400,300));
	editorKit = new HTMLEditorKit();
	gameLog = (HTMLDocument) editorKit.createDefaultDocument();;
	myLogPane.setEditorKit(editorKit);
	myLogPane.setDocument(gameLog);
	myLogScroll = new JScrollPane(myLogPane);
    myLogScroll.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
//	theScrollPane.setPreferredSize(new Dimension(400,400));
	theLogPanel.add(myLogScroll,BorderLayout.CENTER);
    Font font = new Font("Times New Roman", Font.PLAIN, 14);
    String bodyRule = "body { font-family: " + font.getFamily() + "; " +
            "font-size: " + font.getSize() + "pt; }";
    ((HTMLDocument)myLogPane.getDocument()).getStyleSheet().addRule(bodyRule);//	myLogPane.revalidate();
	return theLogPanel;
}
 
源代码2 项目: jeveassets   文件: UpdateTask.java
public void insertLog(final JTextPane jError) {
	if (!log.isEmpty()) {
		StyledDocument doc = new DefaultStyledDocument();
		UpdateTask.this.insertLog(doc);
		jError.setDocument(doc);
	}
}
 
源代码3 项目: Robot-Overlord-App   文件: LogPanel.java
public LogPanel(Translator translator, RobotEntity robot) {
	this.translator = translator;
	this.robot = robot;
	
	// log panel
	Log.addListener(this);

	// the log panel
	log = new JTextPane();
	log.setEditable(false);
	log.setBackground(Color.BLACK);
	kit = new HTMLEditorKit();
	doc = new HTMLDocument();
	log.setEditorKit(kit);
	log.setDocument(doc);
	DefaultCaret caret = (DefaultCaret) log.getCaret();
	caret.setUpdatePolicy(DefaultCaret.ALWAYS_UPDATE);

	JScrollPane logPane = new JScrollPane(log);

	// Now put all the parts together
	panel.setLayout(new GridBagLayout());
	GridBagConstraints con1 = new GridBagConstraints();
	con1.gridx = 0;
	con1.gridy = 0;
	con1.weightx=1;
	con1.weighty=1;
	con1.fill=GridBagConstraints.HORIZONTAL;
	con1.anchor=GridBagConstraints.NORTHWEST;
	panel.add(logPane,con1);
	con1.gridy++;


	con1.weightx=1;
	con1.weighty=0;
	panel.add(getTextInputField(),con1);
	
	// lastly, clear the log
	clearLog();
}
 
源代码4 项目: Rel   文件: BrowserSwing.java
private void setEnhancedOutputStyle(JTextPane pane) {
	pane.setContentType("text/html");
	pane.setEditable(false);
	pane.setEnabled(true);
	HTMLEditorKit editorKit = new HTMLEditorKit();
	HTMLDocument defaultDocument = (HTMLDocument) editorKit.createDefaultDocument();
	pane.setEditorKit(editorKit);
	pane.setDocument(defaultDocument);
	StyleSheet css = editorKit.getStyleSheet();
	for (String entry : style.getFormattedStyle())
		css.addRule(entry);
}
 
源代码5 项目: lizzie   文件: GtpConsolePane.java
/** Creates a Gtp Console Window */
public GtpConsolePane(Window owner) {
  super(owner);
  setTitle("Gtp Console");

  JSONArray pos = WindowPosition.gtpWindowPos();
  if (pos != null) {
    this.setBounds(pos.getInt(0), pos.getInt(1), pos.getInt(2), pos.getInt(3));
  } else {
    Insets oi = owner.getInsets();
    setBounds(
        0,
        owner.getY() - oi.top,
        Math.max(owner.getX() - oi.left, 400),
        Math.max(owner.getHeight() + oi.top + oi.bottom, 300));
  }

  htmlKit = new LizziePane.HtmlKit();
  htmlDoc = (HTMLDocument) htmlKit.createDefaultDocument();
  htmlStyle = htmlKit.getStyleSheet();
  htmlStyle.addRule(Lizzie.config.gtpConsoleStyle);

  console = new JTextPane();
  console.setBorder(BorderFactory.createEmptyBorder());
  console.setEditable(false);
  console.setEditorKit(htmlKit);
  console.setDocument(htmlDoc);
  scrollPane = new JScrollPane();
  scrollPane.setBorder(BorderFactory.createEmptyBorder());
  txtCommand.setBackground(Color.DARK_GRAY);
  txtCommand.setForeground(Color.WHITE);
  lblCommand.setFont(new Font("Tahoma", Font.BOLD, 11));
  lblCommand.setOpaque(true);
  lblCommand.setBackground(Color.DARK_GRAY);
  lblCommand.setForeground(Color.WHITE);
  lblCommand.setText(Lizzie.leelaz == null ? "GTP>" : Lizzie.leelaz.currentShortWeight() + ">");
  pnlCommand.setLayout(new BorderLayout(0, 0));
  pnlCommand.add(lblCommand, BorderLayout.WEST);
  pnlCommand.add(txtCommand);
  getContentPane().add(scrollPane, BorderLayout.CENTER);
  getContentPane().add(pnlCommand, BorderLayout.SOUTH);
  scrollPane.setViewportView(console);
  getRootPane().setBorder(BorderFactory.createEmptyBorder());
  getRootPane().setWindowDecorationStyle(JRootPane.PLAIN_DIALOG);

  txtCommand.addActionListener(e -> postCommand(e));
}
 
源代码6 项目: lizzie   文件: CommentPane.java
/** Creates a window */
public CommentPane(LizzieMain owner) {
  super(owner);
  setLayout(new BorderLayout(0, 0));

  htmlKit = new LizziePane.HtmlKit();
  htmlDoc = (HTMLDocument) htmlKit.createDefaultDocument();
  htmlStyle = htmlKit.getStyleSheet();
  String style =
      "body {background:#"
          + String.format(
              "%02x%02x%02x",
              Lizzie.config.commentBackgroundColor.getRed(),
              Lizzie.config.commentBackgroundColor.getGreen(),
              Lizzie.config.commentBackgroundColor.getBlue())
          + "; color:#"
          + String.format(
              "%02x%02x%02x",
              Lizzie.config.commentFontColor.getRed(),
              Lizzie.config.commentFontColor.getGreen(),
              Lizzie.config.commentFontColor.getBlue())
          + "; font-family:"
          + Lizzie.config.fontName
          + ", Consolas, Menlo, Monaco, 'Ubuntu Mono', monospace;"
          + (Lizzie.config.commentFontSize > 0
              ? "font-size:" + Lizzie.config.commentFontSize
              : "")
          + "}";
  htmlStyle.addRule(style);

  commentPane = new JTextPane();
  commentPane.setBorder(BorderFactory.createEmptyBorder());
  commentPane.setEditorKit(htmlKit);
  commentPane.setDocument(htmlDoc);
  commentPane.setText("");
  commentPane.setEditable(false);
  commentPane.setFocusable(false);
  commentPane.addMouseListener(
      new MouseAdapter() {
        @Override
        public void mouseClicked(MouseEvent e) {
          Lizzie.frame.getFocus();
        }
      });
  scrollPane = new JScrollPane();
  scrollPane.setBorder(BorderFactory.createEmptyBorder());
  scrollPane.setVerticalScrollBarPolicy(
      javax.swing.ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED);
  add(scrollPane);
  scrollPane.setViewportView(commentPane);
  setVisible(false);

  //    mouseMotionAdapter = new MouseMotionAdapter() {
  //      @Override
  //      public void mouseDragged(MouseEvent e) {
  //        System.out.println("Mouse Dragged");
  //        owner.dispatchEvent(e);
  //      }
  //    };
  //    commentPane.addMouseMotionListener(mouseMotionAdapter);
}
 
源代码7 项目: dungeon   文件: SwappingStyledDocument.java
/**
 * Constructs a new SwappingStyleDocument for the provided JTextPane.
 */
public SwappingStyledDocument(JTextPane textPane) {
  this.textPane = textPane;
  textPane.setDocument(activeDocument);
}