Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>In the absence of a good <a href="http://sscce.org/" rel="nofollow">SSCCE</a>, I really don't know how you adding colour to the text on your JTextPane, but hopefully this method might sort things out for you : </p> <pre><code>import javax.swing.text.AttributeSet; import javax.swing.text.SimpleAttributeSet; import javax.swing.text.StyleConstants; import javax.swing.text.StyleContext; private void appendToTextPane(String name, Color c, String f) { StyleContext sc = StyleContext.getDefaultStyleContext(); AttributeSet aset = sc.addAttribute(SimpleAttributeSet.EMPTY, StyleConstants.Foreground, c); aset = sc.addAttribute(aset, StyleConstants.FontFamily, f); int len = Client.nPane.getDocument().getLength(); textPane.setCaretPosition(len); textPane.setCharacterAttributes(aset, true); textPane.replaceSelection(name); } </code></pre> <p>With this you can give a different <code>Color</code> and <code>Font</code> to each <code>String literal</code> that will be added to your JTextPane.</p> <p>Hope this new Code might help you in some way : </p> <pre><code>import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.text.AttributeSet; import javax.swing.text.SimpleAttributeSet; import javax.swing.text.StyleConstants; import javax.swing.text.StyleContext; public class TextPaneTest extends JFrame { private JPanel topPanel; private JPanel bottomPanel; private JTextPane tPane1; private JTextPane tPane2; private JButton button; public TextPaneTest() { topPanel = new JPanel(); topPanel.setLayout(new GridLayout(1, 2)); bottomPanel = new JPanel(); bottomPanel.setBackground(Color.BLACK); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setLocationRelativeTo(null); StyleContext sc = StyleContext.getDefaultStyleContext(); AttributeSet aset = sc.addAttribute(SimpleAttributeSet.EMPTY, StyleConstants.Foreground, Color.BLUE); aset = sc.addAttribute(aset, StyleConstants.FontFamily, "Lucida Console"); tPane1 = new JTextPane(); tPane1.setBorder(BorderFactory.createLineBorder(Color.DARK_GRAY)); tPane1.setCharacterAttributes(aset, false); // Add these settings to the other JTextPane also tPane2 = new JTextPane(); tPane2.setCharacterAttributes(aset, false); // Mimic what the other JTextPane has button = new JButton("ADD TO THE TOP JTEXTPANE"); button.setBackground(Color.DARK_GRAY); button.setForeground(Color.WHITE); button.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { tPane1.setText(tPane2.getText()); } }); add(topPanel, BorderLayout.CENTER); add(bottomPanel, BorderLayout.PAGE_END); topPanel.add(tPane1); topPanel.add(tPane2); bottomPanel.add(button); pack(); tPane2.requestFocusInWindow(); setVisible(true); } public static void main(String... args) { SwingUtilities.invokeLater(new Runnable() { public void run() { new TextPaneTest(); } }); } } </code></pre> <p>Regards</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload