diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatButtonUI.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatButtonUI.java index ec5dd4ea..f6a27663 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatButtonUI.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatButtonUI.java @@ -329,6 +329,11 @@ public class FlatButtonUI } } + @Override + public void paint( Graphics g, JComponent c ) { + super.paint( FlatLabelUI.createGraphicsHTMLTextYCorrection( g, c ), c ); + } + @Override protected void paintText( Graphics g, AbstractButton b, Rectangle textRect, String text ) { if( isHelpButton( b ) ) diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatLabelUI.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatLabelUI.java index 1b4cc2ed..b26853b2 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatLabelUI.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatLabelUI.java @@ -30,7 +30,6 @@ import javax.swing.UIManager; import javax.swing.plaf.ComponentUI; import javax.swing.plaf.basic.BasicHTML; import javax.swing.plaf.basic.BasicLabelUI; -import javax.swing.text.View; import com.formdev.flatlaf.FlatLaf; import com.formdev.flatlaf.util.HiDPIUtils; import com.formdev.flatlaf.util.UIScale; @@ -127,10 +126,15 @@ public class FlatLabelUI BasicHTML.updateRenderer( c, text ); } + static Graphics createGraphicsHTMLTextYCorrection( Graphics g, JComponent c ) { + return (c.getClientProperty( BasicHTML.propertyKey ) != null) + ? HiDPIUtils.createGraphicsTextYCorrection( (Graphics2D) g ) + : g; + } + @Override public void paint( Graphics g, JComponent c ) { - View v = (View) c.getClientProperty( BasicHTML.propertyKey ); - super.paint( (v != null) ? HiDPIUtils.createGraphicsTextYCorrection( (Graphics2D) g ) : g, c ); + super.paint( createGraphicsHTMLTextYCorrection( g, c ), c ); } @Override diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatMenuItemRenderer.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatMenuItemRenderer.java index 064b582f..d1904120 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatMenuItemRenderer.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatMenuItemRenderer.java @@ -40,6 +40,7 @@ import javax.swing.plaf.basic.BasicHTML; import javax.swing.text.View; import com.formdev.flatlaf.FlatLaf; import com.formdev.flatlaf.util.Graphics2DProxy; +import com.formdev.flatlaf.util.HiDPIUtils; /** * Renderer for menu items. @@ -360,7 +361,7 @@ debug*/ if( isArmedOrSelected( menuItem ) && selectionForeground != null ) g = new GraphicsProxyWithTextColor( (Graphics2D) g, selectionForeground ); - htmlView.paint( g, textRect ); + htmlView.paint( HiDPIUtils.createGraphicsTextYCorrection( (Graphics2D) g ), textRect ); } protected static boolean isArmedOrSelected( JMenuItem menuItem ) { diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatProgressBarUI.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatProgressBarUI.java index 705725fd..4ac1efbd 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatProgressBarUI.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatProgressBarUI.java @@ -31,6 +31,7 @@ import javax.swing.LookAndFeel; import javax.swing.UIManager; import javax.swing.plaf.ComponentUI; import javax.swing.plaf.basic.BasicProgressBarUI; +import com.formdev.flatlaf.util.HiDPIUtils; import com.formdev.flatlaf.util.UIScale; /** @@ -194,6 +195,11 @@ public class FlatProgressBarUI } } + @Override + protected void paintString( Graphics g, int x, int y, int width, int height, int amountFull, Insets b ) { + super.paintString( HiDPIUtils.createGraphicsTextYCorrection( (Graphics2D) g ), x, y, width, height, amountFull, b ); + } + @Override protected void setAnimationIndex( int newValue ) { super.setAnimationIndex( newValue ); diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatRadioButtonUI.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatRadioButtonUI.java index ffc2b854..7bde15d2 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatRadioButtonUI.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatRadioButtonUI.java @@ -153,7 +153,7 @@ public class FlatRadioButtonUI } } - super.paint( g, c ); + super.paint( FlatLabelUI.createGraphicsHTMLTextYCorrection( g, c ), c ); } @Override diff --git a/flatlaf-testing/src/main/java/com/formdev/flatlaf/testing/FlatHtmlTest.java b/flatlaf-testing/src/main/java/com/formdev/flatlaf/testing/FlatHtmlTest.java index 0c9e2144..f0c4cac7 100644 --- a/flatlaf-testing/src/main/java/com/formdev/flatlaf/testing/FlatHtmlTest.java +++ b/flatlaf-testing/src/main/java/com/formdev/flatlaf/testing/FlatHtmlTest.java @@ -58,6 +58,34 @@ public class FlatHtmlTest editorPaneLabel = new JLabel(); textPaneLabel = new JLabel(); toolTipLabel = new JLabel(); + panel1 = new JPanel(); + label5 = new JLabel(); + label6 = new JLabel(); + label7 = new JLabel(); + label3 = new JLabel(); + button1 = new JButton(); + button2 = new JButton(); + label11 = new JLabel(); + toggleButton1 = new JToggleButton(); + toggleButton2 = new JToggleButton(); + label12 = new JLabel(); + checkBox1 = new JCheckBox(); + checkBox2 = new JCheckBox(); + label13 = new JLabel(); + radioButton1 = new JRadioButton(); + radioButton2 = new JRadioButton(); + label8 = new JLabel(); + menu1 = new JMenu(); + menu2 = new JMenu(); + label4 = new JLabel(); + menuItem1 = new JMenuItem(); + menuItem2 = new JMenuItem(); + label9 = new JLabel(); + checkBoxMenuItem1 = new JCheckBoxMenuItem(); + checkBoxMenuItem2 = new JCheckBoxMenuItem(); + label10 = new JLabel(); + radioButtonMenuItem1 = new JRadioButtonMenuItem(); + radioButtonMenuItem2 = new JRadioButtonMenuItem(); label1 = new JLabel(); scrollPane15 = new JScrollPane(); editorPane1 = new JEditorPane(); @@ -78,6 +106,7 @@ public class FlatHtmlTest "[fill]" + "[fill]" + "[fill]" + + "[fill]" + "[fill]", // rows "[]" + @@ -100,6 +129,145 @@ public class FlatHtmlTest toolTipLabel.setText("JToolTip:"); add(toolTipLabel, "cell 3 0"); + //======== panel1 ======== + { + panel1.setLayout(new MigLayout( + "insets 0,hidemode 3", + // columns + "[fill]" + + "[fill]" + + "[fill]", + // rows + "[]" + + "[]" + + "[]" + + "[]" + + "[]" + + "[]" + + "[]" + + "[]" + + "[]")); + + //---- label5 ---- + label5.setText("JLabel:"); + panel1.add(label5, "cell 0 0"); + + //---- label6 ---- + label6.setText("Some Bold Text"); + panel1.add(label6, "cell 1 0"); + + //---- label7 ---- + label7.setText("Some text"); + panel1.add(label7, "cell 2 0"); + + //---- label3 ---- + label3.setText("JButon:"); + panel1.add(label3, "cell 0 1"); + + //---- button1 ---- + button1.setText("Some Bold Text"); + panel1.add(button1, "cell 1 1"); + + //---- button2 ---- + button2.setText("Some text"); + panel1.add(button2, "cell 2 1"); + + //---- label11 ---- + label11.setText("text"); + panel1.add(label11, "cell 0 2"); + + //---- toggleButton1 ---- + toggleButton1.setText("Some Bold Text"); + toggleButton1.setSelected(true); + panel1.add(toggleButton1, "cell 1 2"); + + //---- toggleButton2 ---- + toggleButton2.setText("Some text"); + toggleButton2.setSelected(true); + panel1.add(toggleButton2, "cell 2 2"); + + //---- label12 ---- + label12.setText("text"); + panel1.add(label12, "cell 0 3"); + + //---- checkBox1 ---- + checkBox1.setText("Some Bold Text"); + panel1.add(checkBox1, "cell 1 3"); + + //---- checkBox2 ---- + checkBox2.setText("Some text"); + panel1.add(checkBox2, "cell 2 3"); + + //---- label13 ---- + label13.setText("text"); + panel1.add(label13, "cell 0 4"); + + //---- radioButton1 ---- + radioButton1.setText("Some Bold Text"); + panel1.add(radioButton1, "cell 1 4"); + + //---- radioButton2 ---- + radioButton2.setText("Some text"); + panel1.add(radioButton2, "cell 2 4"); + + //---- label8 ---- + label8.setText("JMenu:"); + panel1.add(label8, "cell 0 5"); + + //======== menu1 ======== + { + menu1.setText("Some Bold Text"); + } + panel1.add(menu1, "cell 1 5"); + + //======== menu2 ======== + { + menu2.setText("Some text"); + } + panel1.add(menu2, "cell 2 5"); + + //---- label4 ---- + label4.setText("JMenuItem:"); + panel1.add(label4, "cell 0 6"); + + //---- menuItem1 ---- + menuItem1.setText("Some Bold Text"); + panel1.add(menuItem1, "cell 1 6"); + + //---- menuItem2 ---- + menuItem2.setText("Some text"); + panel1.add(menuItem2, "cell 2 6"); + + //---- label9 ---- + label9.setText("JCheckBoxMenuItem:"); + panel1.add(label9, "cell 0 7"); + + //---- checkBoxMenuItem1 ---- + checkBoxMenuItem1.setText("Some Bold Text"); + checkBoxMenuItem1.setSelected(true); + panel1.add(checkBoxMenuItem1, "cell 1 7"); + + //---- checkBoxMenuItem2 ---- + checkBoxMenuItem2.setText("Some text"); + checkBoxMenuItem2.setSelected(true); + panel1.add(checkBoxMenuItem2, "cell 2 7"); + + //---- label10 ---- + label10.setText("JRadioButtonMenuItem:"); + panel1.add(label10, "cell 0 8"); + + //---- radioButtonMenuItem1 ---- + radioButtonMenuItem1.setText("Some Bold Text"); + radioButtonMenuItem1.setSelected(true); + panel1.add(radioButtonMenuItem1, "cell 1 8"); + + //---- radioButtonMenuItem2 ---- + radioButtonMenuItem2.setText("Some text"); + radioButtonMenuItem2.setSelected(true); + panel1.add(radioButtonMenuItem2, "cell 2 8"); + } + add(panel1, "cell 4 0 1 3,aligny top,growy 0"); + //---- label1 ---- label1.setText("HTML
Sample content
text with link

Header 1

Header 2

Header 3

Header 4

Header 5
Header 6

Paragraph


Col 1Col 2
abcdef
"); add(label1, "cell 0 1"); @@ -183,6 +351,34 @@ public class FlatHtmlTest private JLabel editorPaneLabel; private JLabel textPaneLabel; private JLabel toolTipLabel; + private JPanel panel1; + private JLabel label5; + private JLabel label6; + private JLabel label7; + private JLabel label3; + private JButton button1; + private JButton button2; + private JLabel label11; + private JToggleButton toggleButton1; + private JToggleButton toggleButton2; + private JLabel label12; + private JCheckBox checkBox1; + private JCheckBox checkBox2; + private JLabel label13; + private JRadioButton radioButton1; + private JRadioButton radioButton2; + private JLabel label8; + private JMenu menu1; + private JMenu menu2; + private JLabel label4; + private JMenuItem menuItem1; + private JMenuItem menuItem2; + private JLabel label9; + private JCheckBoxMenuItem checkBoxMenuItem1; + private JCheckBoxMenuItem checkBoxMenuItem2; + private JLabel label10; + private JRadioButtonMenuItem radioButtonMenuItem1; + private JRadioButtonMenuItem radioButtonMenuItem2; private JLabel label1; private JScrollPane scrollPane15; private JEditorPane editorPane1; diff --git a/flatlaf-testing/src/main/java/com/formdev/flatlaf/testing/FlatHtmlTest.jfd b/flatlaf-testing/src/main/java/com/formdev/flatlaf/testing/FlatHtmlTest.jfd index 006018f7..7ff2c3e3 100644 --- a/flatlaf-testing/src/main/java/com/formdev/flatlaf/testing/FlatHtmlTest.jfd +++ b/flatlaf-testing/src/main/java/com/formdev/flatlaf/testing/FlatHtmlTest.jfd @@ -1,11 +1,11 @@ -JFDML JFormDesigner: "7.0.1.0.272" Java: "13.0.2" encoding: "UTF-8" +JFDML JFormDesigner: "7.0.2.0.298" Java: "14" encoding: "UTF-8" new FormModel { contentType: "form/swing" root: new FormRoot { add( new FormContainer( "com.formdev.flatlaf.testing.FlatTestPanel", new FormLayoutManager( class net.miginfocom.swing.MigLayout ) { "$layoutConstraints": "ltr,insets dialog,hidemode 3" - "$columnConstraints": "[fill][fill][fill][fill]" + "$columnConstraints": "[fill][fill][fill][fill][fill]" "$rowConstraints": "[][top][top]" } ) { name: "this" @@ -33,6 +33,183 @@ new FormModel { }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { "value": "cell 3 0" } ) + add( new FormContainer( "javax.swing.JPanel", new FormLayoutManager( class net.miginfocom.swing.MigLayout ) { + "$layoutConstraints": "insets 0,hidemode 3" + "$columnConstraints": "[fill][fill][fill]" + "$rowConstraints": "[][][][][][][][][]" + } ) { + name: "panel1" + add( new FormComponent( "javax.swing.JLabel" ) { + name: "label5" + "text": "JLabel:" + }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { + "value": "cell 0 0" + } ) + add( new FormComponent( "javax.swing.JLabel" ) { + name: "label6" + "text": "Some Bold Text" + }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { + "value": "cell 1 0" + } ) + add( new FormComponent( "javax.swing.JLabel" ) { + name: "label7" + "text": "Some text" + }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { + "value": "cell 2 0" + } ) + add( new FormComponent( "javax.swing.JLabel" ) { + name: "label3" + "text": "JButon:" + }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { + "value": "cell 0 1" + } ) + add( new FormComponent( "javax.swing.JButton" ) { + name: "button1" + "text": "Some Bold Text" + }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { + "value": "cell 1 1" + } ) + add( new FormComponent( "javax.swing.JButton" ) { + name: "button2" + "text": "Some text" + }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { + "value": "cell 2 1" + } ) + add( new FormComponent( "javax.swing.JLabel" ) { + name: "label11" + "text": "text" + }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { + "value": "cell 0 2" + } ) + add( new FormComponent( "javax.swing.JToggleButton" ) { + name: "toggleButton1" + "text": "Some Bold Text" + "selected": true + }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { + "value": "cell 1 2" + } ) + add( new FormComponent( "javax.swing.JToggleButton" ) { + name: "toggleButton2" + "text": "Some text" + "selected": true + }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { + "value": "cell 2 2" + } ) + add( new FormComponent( "javax.swing.JLabel" ) { + name: "label12" + "text": "text" + }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { + "value": "cell 0 3" + } ) + add( new FormComponent( "javax.swing.JCheckBox" ) { + name: "checkBox1" + "text": "Some Bold Text" + }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { + "value": "cell 1 3" + } ) + add( new FormComponent( "javax.swing.JCheckBox" ) { + name: "checkBox2" + "text": "Some text" + }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { + "value": "cell 2 3" + } ) + add( new FormComponent( "javax.swing.JLabel" ) { + name: "label13" + "text": "text" + }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { + "value": "cell 0 4" + } ) + add( new FormComponent( "javax.swing.JRadioButton" ) { + name: "radioButton1" + "text": "Some Bold Text" + }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { + "value": "cell 1 4" + } ) + add( new FormComponent( "javax.swing.JRadioButton" ) { + name: "radioButton2" + "text": "Some text" + }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { + "value": "cell 2 4" + } ) + add( new FormComponent( "javax.swing.JLabel" ) { + name: "label8" + "text": "JMenu:" + }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { + "value": "cell 0 5" + } ) + add( new FormContainer( "javax.swing.JMenu", new FormLayoutManager( class javax.swing.JMenu ) ) { + name: "menu1" + "text": "Some Bold Text" + }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { + "value": "cell 1 5" + } ) + add( new FormContainer( "javax.swing.JMenu", new FormLayoutManager( class javax.swing.JMenu ) ) { + name: "menu2" + "text": "Some text" + }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { + "value": "cell 2 5" + } ) + add( new FormComponent( "javax.swing.JLabel" ) { + name: "label4" + "text": "JMenuItem:" + }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { + "value": "cell 0 6" + } ) + add( new FormComponent( "javax.swing.JMenuItem" ) { + name: "menuItem1" + "text": "Some Bold Text" + }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { + "value": "cell 1 6" + } ) + add( new FormComponent( "javax.swing.JMenuItem" ) { + name: "menuItem2" + "text": "Some text" + }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { + "value": "cell 2 6" + } ) + add( new FormComponent( "javax.swing.JLabel" ) { + name: "label9" + "text": "JCheckBoxMenuItem:" + }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { + "value": "cell 0 7" + } ) + add( new FormComponent( "javax.swing.JCheckBoxMenuItem" ) { + name: "checkBoxMenuItem1" + "text": "Some Bold Text" + "selected": true + }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { + "value": "cell 1 7" + } ) + add( new FormComponent( "javax.swing.JCheckBoxMenuItem" ) { + name: "checkBoxMenuItem2" + "text": "Some text" + "selected": true + }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { + "value": "cell 2 7" + } ) + add( new FormComponent( "javax.swing.JLabel" ) { + name: "label10" + "text": "JRadioButtonMenuItem:" + }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { + "value": "cell 0 8" + } ) + add( new FormComponent( "javax.swing.JRadioButtonMenuItem" ) { + name: "radioButtonMenuItem1" + "text": "Some Bold Text" + "selected": true + }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { + "value": "cell 1 8" + } ) + add( new FormComponent( "javax.swing.JRadioButtonMenuItem" ) { + name: "radioButtonMenuItem2" + "text": "Some text" + "selected": true + }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { + "value": "cell 2 8" + } ) + }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { + "value": "cell 4 0 1 3,aligny top,growy 0" + } ) add( new FormComponent( "javax.swing.JLabel" ) { name: "label1" "text": "HTML
Sample content
text with link

Header 1

Header 2

Header 3

Header 4

Header 5
Header 6

Paragraph


Col 1Col 2
abcdef
"