package ui.view; import java.awt.Color; import javax.swing.JScrollPane; import java.awt.BorderLayout; import javax.swing.JTextPane; import javax.swing.text.BadLocationException; import javax.swing.text.Style; import javax.swing.text.StyleConstants; import javax.swing.text.StyledDocument; import javax.swing.JPanel; public class Console extends JScrollPane { /** * */ private static final long serialVersionUID = 1L; private final JTextPane consoleText = new JTextPane(); private final JPanel panel = new JPanel(); private Style style; private StyledDocument doc; public Console() { super(); this.setBackground(Color.WHITE); consoleText.setForeground(Color.BLACK); consoleText.setEditable(false); doc = consoleText.getStyledDocument(); style = consoleText.addStyle("I'm a Style", null); this.setViewportView(panel); panel.setLayout(new BorderLayout(0, 0)); panel.setBackground(Color.WHITE); panel.add(consoleText); setViewportView(panel); } public void addText(String t, Color c, int p) { StyleConstants.setForeground(style, c); StyleConstants.setFontSize(style, p); try { if (consoleText.getText().length() != 0) { doc.insertString(doc.getLength(), "\n", style); } doc.insertString(doc.getLength(), t, style); } catch (BadLocationException e) { } } }