Open Sciss opened 5 years ago
WebTable
example looks good because it uses the feature I've mentioned on our chat earlier:
@NotNull
@Override
protected List<? extends JComponent> createPreviewElements ()
{
final WebTable table = new WebTable ( getStyleId (), SampleData.createShortTableModel ( false ) );
table.optimizeColumnWidths ( true );
table.setOptimizeRowHeight ( true );
return CollectionUtils.asList ( table );
}
The row height optimization one.
Although you've made a good point that default row height might not have effect until set explicitely - i'll double check that tomorrow and see if it's true for all or at least some platforms/L&Fs and whether something can be improved or not.
I have double-checked - normal JTable
with no settings doesn't scale row height at all, so whether it is specified in style or not doesn't really affect the outcome.
Here is a small example I tried on Windows (with Metal L&F):
public static void main ( final String[] args )
{
SwingTest.run ( MetalLookAndFeel.class.getCanonicalName (), new Runnable ()
{
@Override
public void run ()
{
final JTable table = new JTable (
new Object[][]{
{ "Col 1", "Col 2", true },
{ "Col 1", "Col 2", false }
},
new Object[]{ "Col 1", "Col 2", "Col 3" }
);
TestFrame.show ( new JScrollPane ( table ) );
}
} );
}
Result is a simple metal-styled table:
Now let's say table has large font:
public static void main ( final String[] args )
{
SwingTest.run ( MetalLookAndFeel.class.getCanonicalName (), new Runnable ()
{
@Override
public void run ()
{
final JTable table = new JTable (
new Object[][]{
{ "Col 1", "Col 2", true },
{ "Col 1", "Col 2", false }
},
new Object[]{ "Col 1", "Col 2", "Col 3" }
);
table.setFont ( table.getFont ().deriveFont ( 40f ) );
TestFrame.show ( new JScrollPane ( table ) );
}
} );
}
Result is:
The same happens even if I make native font large, it doesn't really matter - default JTable
never scales row height with it's content. And table only allows positive row height, so there is no hack for -1
height or anything like that like in other components:
public void setRowHeight(int rowHeight) {
if (rowHeight <= 0) {
throw new IllegalArgumentException("New row height less than 1");
}
...
}
ok, thanks for checking
The whole reason for adding TableRowHeightOptimizer
utility was inability of JTable
to scale with renderer size correctly. It's not a perfect solution, but unfortunately I didn't find a better way to do it yet.
I'll actually change this to enhancement and leave it be for possible future improvements since there already are examples & screenshots here.
I'm still not sure you need to explicitly set a row-height, I think other look-and-feels do not need that either. Yes, default sets 16, but rowHeightSet is still false.
The result is that on Linux the default font is relatively large and
JTable
looks bad:whereas
WebTable
looks good:I think
JTable
should not require per-platform row-height tweaking, but should just take the actual font size into account.