0

In Java I use

UIManager.setLookAndFeel(
                    UIManager.getSystemLookAndFeelClassName()

to get the System Look and Feel

However I am using a JTable and having problem on Windows with the Windows LAF and OSX with the OSX LAF, all the problem look to be solved if I just use the

UIManager.getCrossPlatformLookAndFeelClassName();

Is it possible to just have my JTable and the JScrollPane it is wrapped in use the Cross Platform Look and Feel without it affecting anything else or not.

And if so is this a really bad idea ?

The problems I am seeing are

Windows, Column Header rendering almost indistinguisable from regular table cells

OSX, Cell background colour same as panel background

OSX, No grid lines between table cells.

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
Paul Taylor
  • 13,411
  • 42
  • 184
  • 351

1 Answers1

1

The LAF of a component is determined at the time the component is created.

So you can try something like:

  1. set temporary LAF
  2. create components and add them to the frame.
  3. restore the LAF

And if so is this a really bad idea ?

Not sure if there are an hidden problems.

camickr
  • 321,443
  • 19
  • 166
  • 288
  • thx Ill try, btw I had a problem with your TableAdjuster code, dunno if you are interested - https://stackoverflow.com/questions/49781385/why-cant-i-deselect-select-jtable-boolean-field-reliably-using-mouse – Paul Taylor Apr 17 '18 at 17:02
  • It sort of works, doesnt break other components but now on OSX selection colour is wrong, also confusingly the tableheaders on OSX look different to tableheader so WIndows even though both using System LAF. Disappointed that JTable still seems to have the same issues it had 10 years ago – Paul Taylor Apr 17 '18 at 17:32
  • `I had a problem with your TableAdjuster code` - as Andrew stated you didn't post an MCVE/SSCCE so I can't really help. Adjusting the width of columns has no effect on the editors used by the table. Your code uses custom logic for the editors TableModel etc so you need to look there. As you stated, when you created the SSCCE you could not reproduce the problem. Neither can I. – camickr Apr 17 '18 at 18:31
  • `confusingly the tableheaders ` - not sure when the JTableHeader is created. It may not be created when the table is created. I believe the table header is added to the scrollpane when the scrollpane is added to a visible frame, so that could be the issue. `OSX selection colour is wrong,` - the default selection color may come from the UIDefaults at the time it is painted. Maybe you manually need to set the selection color when you create the table. In any case it seems like more of a hack to get it to work. – camickr Apr 17 '18 at 18:41
  • 1
    *"Not sure if there are an hidden problems."* The queen of the Nile [says yes](https://stackoverflow.com/a/18427362/418556). Best approach is to customize one PLAF with the parts of the other PLAF you'd like to be different. – Andrew Thompson Apr 18 '18 at 04:11
  • My gut feeling was that it was a bad idea, I think I will go back to the System LAF for and work on each problem one by one. – Paul Taylor Apr 18 '18 at 08:09
  • Found the problem with no grid on OSX not only do you need to setShowGrid() but also setGridColor() because both cells and grid color default to white ! – Paul Taylor Apr 18 '18 at 08:48