For some reason my text pane is white. It's a text pane (output) nested inside aj scrollpane.
jScrollPane1.setBackground(new java.awt.Color(0, 0, 0));
jScrollPane1.setBorder(null);
jScrollPane1.setOpaque(false);
output.setEditable(false);
output.setBackground(new java.awt.Color(0, 0, 0));
output.setBorder(null);
output.setCaretColor(new java.awt.Color(255, 255, 255));
output.setDisabledTextColor(new java.awt.Color(0, 0, 0));
output.setHighlighter(null);
output.setOpaque(false);
jScrollPane1.setViewportView(output);
That's the only code affecting it. I don't know why this is happening, but I want the text pane to be black.
First of all, setting the background color of the JTextPane
should be more than enough
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTextPane;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
public class BlackTextPane {
public static void main(String[] args) {
new BlackTextPane();
}
public BlackTextPane() {
EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException ex) {
}
JTextPane tp = new JTextPane();
tp.setForeground(Color.WHITE);
tp.setBackground(Color.BLACK);
JFrame frame = new JFrame("Testing");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLayout(new BorderLayout());
frame.add(new JScrollPane(tp));
frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
});
}
}
How ever, you seem to making it transparent for some reason, output.setOpaque(false);
. Now you've made the JScrollPane
transparent as well, which is good, but you forgot to make the view port transparent jScrollPane1.getViewport().setOpaque(false);
Scroll panes are made up three components, the JScrollPane
itself, the JViewport
which determines what gets displayed and you component (the view)
Take a closer look at How to Use Scroll Panes for more details
Set the look and feel from "Nimbus" to "Windows" and make sure the Text Pane's "Opaque" is true.
Don't worry, these errors happen when you code at 1 in the morning.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.