Java Code Examples for javax.swing.JTextPane#setDocument()

The following examples show how to use javax.swing.JTextPane#setDocument() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DomGameFrame.java    From DominionSim with MIT License 6 votes vote down vote up
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;
}
 
Example 2
Source File: UpdateTask.java    From jeveassets with GNU General Public License v2.0 5 votes vote down vote up
public void insertLog(final JTextPane jError) {
	if (!log.isEmpty()) {
		StyledDocument doc = new DefaultStyledDocument();
		UpdateTask.this.insertLog(doc);
		jError.setDocument(doc);
	}
}
 
Example 3
Source File: LogPanel.java    From Robot-Overlord-App with GNU General Public License v2.0 5 votes vote down vote up
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();
}
 
Example 4
Source File: BrowserSwing.java    From Rel with Apache License 2.0 5 votes vote down vote up
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);
}
 
Example 5
Source File: GtpConsolePane.java    From lizzie with GNU General Public License v3.0 4 votes vote down vote up
/** 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));
}
 
Example 6
Source File: CommentPane.java    From lizzie with GNU General Public License v3.0 4 votes vote down vote up
/** 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);
}
 
Example 7
Source File: SwappingStyledDocument.java    From dungeon with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 * Constructs a new SwappingStyleDocument for the provided JTextPane.
 */
public SwappingStyledDocument(JTextPane textPane) {
  this.textPane = textPane;
  textPane.setDocument(activeDocument);
}