Closed ijabz closed 2 years ago
Is there an easy way to support striped lists where striping is shown for whole list even if has no/view rows, like Finder does on MacOS?
No.
You could either subclass JList
and override paintComponent(Graphics)
or subclass FlatListUI
and override paint(Graphics, JComponent)
and paint the stripes below the last list item yourself.
You need to check whether the list is in a scroll pane and whether the scroll pane is larger than the list. Get cell bounds of last list item. Then you know where to start painting and the the height of a row.
Okay, wouldnt this be a worthy addition to Flatlaf then? If the idea is for Flatlaf to be suitable for all platforms then for Mac users it needs to like a antive mac app, otherwise they wont like it
Okay, wouldnt this be a worthy addition to Flatlaf then?
Well maybe, but JList
does not support stripping out of the box.
That's something you've added in your renderer 😉
So the list does not know for sure whether to paint stripes or not.
If the idea is for Flatlaf to be suitable for all platforms then for Mac users it needs to like a antive mac app, otherwise they wont like it
Actually don't see stripes in lists in native macOS apps. Only tables have stripes.
Are you talking about JTable
?
Actually I meant both, if you go tot Finder Preferences and click on Tags that looks like a list to me and is striped. My point applies to JTable so could you explain the best way to do that. FWIW the Quaqua look and Feel that I used many years ago did support striping - https://www.randelshofer.ch/quaqua/guide/index.html
Seems that macOS does not have a separate "list" control. Only a table view (see NSTableView), where you can enable alternate row coloring with usesAlternatingRowBackgroundColors property.
The Apple Human Interface Guidelines for Table Views notes:
Consider using alternating row colors in multicolumn table views. Alternating colors make it easier to track row values across columns especially in wide table views.
That's probably the reason why single column lists/tables do not use alternating row coloring on macOS.
I'll try to extend JTable
painting...
Thanks for looking into this, okay I have removed striping from lists
Now I have noticed that if I just set
UIManager.put("Table.alternateRowColor", DarkMode.macosVeryDarkGray);
and use a standard JTable it will do striping for actual rows.
However i have an editable table and for that I thought it would be helpful to show gridlines, but with an alternate row color set it only shows grid lines for part of the grid
Just to be clear Im using in two different types of table, one that always of the size that matches the number of rows and for this the existing rendering works okay except for the problem with grid lines, and another which can be larger than number of rows and for that it is a problem that the table is not striped throughout, so the original problem remains but there seems to be additional problem with using grid lines with striping
You need to increase table intercell spacing (default is 0,0
) for grid lines with striping:
table.setIntercellSpacing( new Dimension( 1, 1 ) );
Thanks, that works but I can suggest you add it to https://www.formdev.com/flatlaf/components/table/ as I dont think most users would know that.
This is now available in FlatLaf 2.3.
It is disabled by default because there is some risk that it does not work as expected because alternate row painting is done in two places:
DefaultTableCellRenderer
for table cellsFlatTableUI
for the area below the table if table is smaller than scroll paneSo if a custom table cell renderer is used, that e.g. does not support alternate row painting, then it would be look ugly to have alternate rows painted below the table...
To enable use:
UIManager.put( "Table.paintOutsideAlternateRows", true );
UIManager.put( "Table.alternateRowColor", new Color( 0xeeeeee ) );
Is there an easy way to support striped lists where striping is shown for whole list even if has no/view rows, like Finder does on MacOS?
Currently can stripe my lists, but only striped for where we have data not the whole window, doing as follows:
When I configure FlatLaf
UIManager.put("Table.alternateRowColor", DarkMode.macosVeryDarkGray);
...Use the following renderer for my list