avoid painting text with our rendering hints enabled to avoid antialiased text in some components if text antialiasing is disabled in system (issue #227)

This commit is contained in:
Karl Tauber
2020-12-18 12:17:43 +01:00
parent 460f0d9dee
commit 956001dbd7
13 changed files with 237 additions and 45 deletions

View File

@@ -21,6 +21,7 @@ import javax.swing.*;
import com.formdev.flatlaf.util.StringUtils;
import com.formdev.flatlaf.util.UIScale;
import net.miginfocom.swing.*;
import org.jdesktop.swingx.*;
/**
* @author Karl Tauber
@@ -89,6 +90,12 @@ public class FlatHtmlTest
label14 = new JLabel();
label15 = new JLabel();
label16 = new JLabel();
label17 = new JLabel();
comboBox1 = new JComboBox<>();
comboBox2 = new JComboBox<>();
label18 = new JLabel();
xHyperlink1 = new JXHyperlink();
xHyperlink2 = new JXHyperlink();
label1 = new JLabel();
scrollPane15 = new JScrollPane();
editorPane1 = new JEditorPane();
@@ -150,6 +157,8 @@ public class FlatHtmlTest
"[]" +
"[]" +
"[]" +
"[]" +
"[]" +
"[]"));
//---- label5 ----
@@ -283,6 +292,38 @@ public class FlatHtmlTest
label16.setText("(move mouse here)");
label16.setToolTipText("Some text");
panel1.add(label16, "cell 2 9");
//---- label17 ----
label17.setText("JComboBox:");
panel1.add(label17, "cell 0 10");
//---- comboBox1 ----
comboBox1.setModel(new DefaultComboBoxModel<>(new String[] {
"<html>Some <b>Bold</b> Text",
"abc",
"def"
}));
panel1.add(comboBox1, "cell 1 10");
//---- comboBox2 ----
comboBox2.setModel(new DefaultComboBoxModel<>(new String[] {
"Some Text",
"abc",
"def"
}));
panel1.add(comboBox2, "cell 2 10");
//---- label18 ----
label18.setText("JXHyperlink:");
panel1.add(label18, "cell 0 11");
//---- xHyperlink1 ----
xHyperlink1.setText("<html>Some <b>Bold</b> Text");
panel1.add(xHyperlink1, "cell 1 11");
//---- xHyperlink2 ----
xHyperlink2.setText("Some text");
panel1.add(xHyperlink2, "cell 2 11");
}
add(panel1, "cell 4 0 1 3,aligny top,growy 0");
@@ -400,6 +441,12 @@ public class FlatHtmlTest
private JLabel label14;
private JLabel label15;
private JLabel label16;
private JLabel label17;
private JComboBox<String> comboBox1;
private JComboBox<String> comboBox2;
private JLabel label18;
private JXHyperlink xHyperlink1;
private JXHyperlink xHyperlink2;
private JLabel label1;
private JScrollPane scrollPane15;
private JEditorPane editorPane1;

View File

@@ -1,4 +1,4 @@
JFDML JFormDesigner: "7.0.2.0.298" Java: "14" encoding: "UTF-8"
JFDML JFormDesigner: "7.0.3.1.342" Java: "15" encoding: "UTF-8"
new FormModel {
contentType: "form/swing"
@@ -36,7 +36,7 @@ new FormModel {
add( new FormContainer( "javax.swing.JPanel", new FormLayoutManager( class net.miginfocom.swing.MigLayout ) {
"$layoutConstraints": "insets 0,hidemode 3"
"$columnConstraints": "[fill][fill][fill]"
"$rowConstraints": "[][][][][][][][][][]"
"$rowConstraints": "[][][][][][][][][][][][]"
} ) {
name: "panel1"
add( new FormComponent( "javax.swing.JLabel" ) {
@@ -227,6 +227,52 @@ new FormModel {
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 2 9"
} )
add( new FormComponent( "javax.swing.JLabel" ) {
name: "label17"
"text": "JComboBox:"
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 0 10"
} )
add( new FormComponent( "javax.swing.JComboBox" ) {
name: "comboBox1"
"model": new javax.swing.DefaultComboBoxModel {
selectedItem: "<html>Some <b>Bold</b> Text"
addElement( "<html>Some <b>Bold</b> Text" )
addElement( "abc" )
addElement( "def" )
}
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 1 10"
} )
add( new FormComponent( "javax.swing.JComboBox" ) {
name: "comboBox2"
"model": new javax.swing.DefaultComboBoxModel {
selectedItem: "Some Text"
addElement( "Some Text" )
addElement( "abc" )
addElement( "def" )
}
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 2 10"
} )
add( new FormComponent( "javax.swing.JLabel" ) {
name: "label18"
"text": "JXHyperlink:"
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 0 11"
} )
add( new FormComponent( "org.jdesktop.swingx.JXHyperlink" ) {
name: "xHyperlink1"
"text": "<html>Some <b>Bold</b> Text"
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 1 11"
} )
add( new FormComponent( "org.jdesktop.swingx.JXHyperlink" ) {
name: "xHyperlink2"
"text": "Some text"
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 2 11"
} )
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 4 0 1 3,aligny top,growy 0"
} )
@@ -296,7 +342,7 @@ new FormModel {
} )
}, new FormLayoutConstraints( null ) {
"location": new java.awt.Point( 0, 0 )
"size": new java.awt.Dimension( 695, 755 )
"size": new java.awt.Dimension( 820, 755 )
} )
}
}

View File

@@ -68,6 +68,9 @@ public class FlatTestFrame
public boolean applyComponentOrientationToFrame;
public static FlatTestFrame create( String[] args, String title ) {
// disable text antialiasing
// System.setProperty( "awt.useSystemAAFontSettings", "off" );
DemoPrefs.init( PREFS_ROOT_PATH );
// set scale factor