Когда я добавляю белый текст на черный JTextPane, цвет шрифта становится неоднородным, что приводит к размытости. Если я использую drawString в том же JTextPane, текст будет хорошо нарисован.
Изменение ANTIALIASING не решает проблему.
Код - простой пример моей проблемы, вот что я получаю:
Спасибо всем
public final class Example extends JTextPane {
public static void main(String... aArgs){
new Example();
}
Example() {
JFrame mainFrame= new JFrame();
mainFrame.setSize(200,200);
mainFrame.getContentPane().setLayout(new BorderLayout());
mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
mainFrame.setVisible(true);
setBackground(Color.black);
StyledDocument doc = getStyledDocument();
Style style = addStyle("I'm a Style", null);
StyleConstants.setForeground(style, Color.white);
StyleConstants.setFontFamily(style,"Courier New");
StyleConstants.setFontSize(style, 20);
try { doc.insertString(doc.getLength(), " Example1",style); }
catch (BadLocationException e){}
mainFrame.getContentPane().add(this);
}
public void paintComponent(Graphics g) {
Graphics2D graphics2d = (Graphics2D) g;
graphics2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
graphics2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
graphics2d.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS,
RenderingHints.VALUE_FRACTIONALMETRICS_ON);
super.paintComponent(graphics2d);
graphics2d.setColor(Color.white);
Font courier = new Font("Courier New",0,20);
graphics2d.setFont(courier.deriveFont(20));
graphics2d.drawString(" Example2", 0, 150);
}
}