weisJ / darklaf

Darklaf - A themeable swing Look and Feel based on Darcula-Laf
MIT License
438 stars 40 forks source link

[JTable] text shifts up when start editing and rowHeight is odd #126

Open vlsi opened 4 years ago

vlsi commented 4 years ago

Test case:

1) Add the following to TableDemo

```java
// Ensure row height is not divisible by 2
table.setRowHeight(table.getRowHeight() | 1);
```

2) Try editing the cells

Actual results: text in editable fields moves up by 1px or so.

Just in case you wonder: JMeter adjusts rowHeight based on the font size and zoom level. At certain zoom levels the computed rowHeight becomes odd.

weisJ commented 4 years ago

Does this happen with the default font size or only a specific one? I'm not getting this behaviour in windows with the default size. You may also try to remove #patchMacOsFonts to see is related to the system font.

vlsi commented 4 years ago

This happens with the default font in macOS.

vlsi commented 4 years ago

You may also try to remove #patchMacOsFonts to see is related to the system font.

I've removed patchMacOsFonts and the issue is still there.

weisJ commented 4 years ago

What baseline does the macOS system font have for standard text characters i.e. what does Font#getBaselineFor return?

vlsi commented 4 years ago
font.getBaselineFor('a') = 0 javax.swing.plaf.FontUIResource[family=Lucida Grande,name=Lucida Grande,style=plain,size=12]
font.getBaselineFor('a') = 0 javax.swing.plaf.FontUIResource[family=Dialog,name=Dialog,style=plain,size=12]
weisJ commented 4 years ago

How about the font height? I suspect that the issue is that the font is generally shifted in textfields with odd height.

vlsi commented 4 years ago
Font f = defaults.getFont("Table.font");
System.out.println("f = " + f);
System.out.println("font.getBaselineFor('a') = " + f.getBaselineFor('a'));
System.out.println(
"FontDesignMetrics.getMetrics(font).getHeight() = " + FontDesignMetrics.getMetrics(f).getHeight());

=>

f = javax.swing.plaf.FontUIResource[family=.SF NS Text,name=.SF NS Text,style=plain,size=12]
font.getBaselineFor('a') = 0
FontDesignMetrics.getMetrics(font).getHeight() = 15
weisJ commented 4 years ago

Please add

    @Override
    protected Rectangle getVisibleEditorRect() {
        Rectangle rect = super.getVisibleEditorRect();
        System.out.println(rect);
        return rect;
    }

in DarkTextUI. What is returned for odd/even row height?

vlsi commented 4 years ago
table.getRowHeight() = 23
java.awt.Rectangle[x=5,y=2,width=78,height=18]
table.getRowHeight() = 22
java.awt.Rectangle[x=5,y=2,width=78,height=17]
weisJ commented 4 years ago

Is the issue still occurring? When increasing the rowHeight in TableDemo the Text should only change position every two steps.