From 8d1ce46d095de9da197298fa9fc3022bdf0e453c Mon Sep 17 00:00:00 2001 From: May Date: Tue, 25 Apr 2023 14:19:41 -0400 Subject: [PATCH] Fix problem with setForeground and setBackground --- .../openrocket/gui/components/DescriptionArea.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/swing/src/net/sf/openrocket/gui/components/DescriptionArea.java b/swing/src/net/sf/openrocket/gui/components/DescriptionArea.java index 39ca75da0..2c666eff2 100644 --- a/swing/src/net/sf/openrocket/gui/components/DescriptionArea.java +++ b/swing/src/net/sf/openrocket/gui/components/DescriptionArea.java @@ -18,6 +18,9 @@ import java.io.FileOutputStream; import javax.swing.JTextPane; import javax.swing.event.HyperlinkEvent; import javax.swing.event.HyperlinkListener; +import javax.swing.text.SimpleAttributeSet; +import javax.swing.text.StyleConstants; +import javax.swing.text.StyledDocument; import javax.swing.JEditorPane; import javax.swing.JPanel; import javax.swing.JScrollPane; @@ -188,6 +191,7 @@ public class DescriptionArea extends JScrollPane { } }); + setForeground(editorPane.getForeground()); editorPane.scrollRectToVisible(new Rectangle(0, 0, 1, 1)); } @@ -206,11 +210,19 @@ public class DescriptionArea extends JScrollPane { public void setBackground(Color color) { if (editorPane == null) return; editorPane.setBackground(color); + StyledDocument styledDocument = (StyledDocument) editorPane.getDocument(); + SimpleAttributeSet attributeSet = new SimpleAttributeSet(); + StyleConstants.setForeground(attributeSet, color); + styledDocument.setCharacterAttributes(0, styledDocument.getLength(), attributeSet, false); } public void setForeground(Color color) { if (editorPane == null) return; editorPane.setForeground(color); + StyledDocument styledDocument = (StyledDocument) editorPane.getDocument(); + SimpleAttributeSet attributeSet = new SimpleAttributeSet(); + StyleConstants.setForeground(attributeSet, color); + styledDocument.setCharacterAttributes(0, styledDocument.getLength(), attributeSet, false); } }