mirror of
https://github.com/JFormDesigner/FlatLaf.git
synced 2025-12-08 23:08:42 +03:00
MenuItem: fixed sometimes wrapped HTML text on HiDPI screens on Windows
This commit is contained in:
@@ -7,6 +7,7 @@ FlatLaf Change Log
|
||||
|
||||
- ComboBox: Fixed vertical alignment of text in popup list with text in combo
|
||||
box in IntelliJ/Darcula themes.
|
||||
- MenuItem: Fixed sometimes wrapped HTML text on HiDPI screens on Windows.
|
||||
- TableHeader: Fixed exception when changing table structure (e.g. removing
|
||||
column) from a table header popup menu action. (issue #532)
|
||||
- `HiDPIUtils.paintAtScale1x()` now supports rotated graphics. (issue #557)
|
||||
|
||||
@@ -446,6 +446,19 @@ debug*/
|
||||
protected static void paintHTMLText( Graphics g, JMenuItem menuItem,
|
||||
Rectangle textRect, View htmlView, Color selectionForeground )
|
||||
{
|
||||
// On Windows, using Segoe UI font, Java 15 or older and scaling greater than 1,
|
||||
// the width of the HTML view may be initially too small (because component
|
||||
// is not connected to a GraphicsConfiguration when getPreferredSize() is invoked).
|
||||
// Since Java 16, this seems to be fixed somehow by doing popup menu layout twice.
|
||||
//
|
||||
// If using a too small width for htmlView.paint(), the view would rearrange
|
||||
// its children and wrap them to two lines. To avoid this, use view preferred X span
|
||||
// for painting. Core Lafs actually do the same in class MenuItemLayoutHelper.
|
||||
//
|
||||
// Example HTML text that causes the problem: "<html>some <b>HTML</b> <i>text</i></html>"
|
||||
textRect = new Rectangle( textRect );
|
||||
textRect.width = (int) htmlView.getPreferredSpan( View.X_AXIS );
|
||||
|
||||
if( isArmedOrSelected( menuItem ) && selectionForeground != null )
|
||||
g = new GraphicsProxyWithTextColor( (Graphics2D) g, selectionForeground );
|
||||
|
||||
|
||||
@@ -181,6 +181,10 @@ public class FlatMenusTest
|
||||
JMenuItem menuItem45 = new JMenuItem();
|
||||
JMenuItem menuItem46 = new JMenuItem();
|
||||
JMenuItem menuItem47 = new JMenuItem();
|
||||
JMenu menu13 = new JMenu();
|
||||
JMenuItem menuItem48 = new JMenuItem();
|
||||
JMenuItem menuItem49 = new JMenuItem();
|
||||
JMenuItem menuItem50 = new JMenuItem();
|
||||
menuBar2 = new JMenuBar();
|
||||
JMenu menu8 = new JMenu();
|
||||
FlatMenusTest.LargerMenuItem menuItem13 = new FlatMenusTest.LargerMenuItem();
|
||||
@@ -442,6 +446,24 @@ public class FlatMenusTest
|
||||
menu12.add(menuItem47);
|
||||
}
|
||||
menuBar1.add(menu12);
|
||||
|
||||
//======== menu13 ========
|
||||
{
|
||||
menu13.setText("HTML");
|
||||
|
||||
//---- menuItem48 ----
|
||||
menuItem48.setText("<html>some <b color=\"red\">HTML</b> <i color=\"blue\">text</i></html>");
|
||||
menu13.add(menuItem48);
|
||||
|
||||
//---- menuItem49 ----
|
||||
menuItem49.setText("<html>some longer <b color=\"red\">HTML</b> <i color=\"blue\">text</i></html>");
|
||||
menu13.add(menuItem49);
|
||||
|
||||
//---- menuItem50 ----
|
||||
menuItem50.setText("<html>another <b color=\"red\">HTML</b> <i color=\"blue\">text</i></html>");
|
||||
menu13.add(menuItem50);
|
||||
}
|
||||
menuBar1.add(menu13);
|
||||
}
|
||||
add(menuBar1, "cell 1 0 2 1,growx");
|
||||
|
||||
|
||||
@@ -194,6 +194,22 @@ new FormModel {
|
||||
"icon": new com.jformdesigner.model.SwingIcon( 0, "/com/formdev/flatlaf/testing/test64.png" )
|
||||
} )
|
||||
} )
|
||||
add( new FormContainer( "javax.swing.JMenu", new FormLayoutManager( class javax.swing.JMenu ) ) {
|
||||
name: "menu13"
|
||||
"text": "HTML"
|
||||
add( new FormComponent( "javax.swing.JMenuItem" ) {
|
||||
name: "menuItem48"
|
||||
"text": "<html>some <b color=\"red\">HTML</b> <i color=\"blue\">text</i></html>"
|
||||
} )
|
||||
add( new FormComponent( "javax.swing.JMenuItem" ) {
|
||||
name: "menuItem49"
|
||||
"text": "<html>some longer <b color=\"red\">HTML</b> <i color=\"blue\">text</i></html>"
|
||||
} )
|
||||
add( new FormComponent( "javax.swing.JMenuItem" ) {
|
||||
name: "menuItem50"
|
||||
"text": "<html>another <b color=\"red\">HTML</b> <i color=\"blue\">text</i></html>"
|
||||
} )
|
||||
} )
|
||||
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
||||
"value": "cell 1 0 2 1,growx"
|
||||
} )
|
||||
|
||||
Reference in New Issue
Block a user