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