0

I am using swingx library, on Windows I am now moving towards using the Flatlaf light and dark look and feel on all platforms

This looks fine on MacOS, but on Windows the status bar looks like it did with Windows look and feel and doesn't look right.

enter image description here

It is because I'm using the swingx JXStatusBar component and this has some look and feel enhancements including some Windows specific images used for the background

e.g. swingx\swingx-core\src\main\resources\org\jdesktop\swingx\plaf\windows\resources\silver-statusbar-left.png

Trying to change the background colour of the component or the labels I add to it has no effect.

So I thought the best thing to do was move away from using JXStatusBar and just use a JPanel, but continue adding the components in same way using JXStatusBar.Constraint

        component = new JPanel();
        .....
        JXStatusBar.Constraint c1 = new JXStatusBar.Constraint();
        c1.setFixedWidth(100);
        component.add(statusLabel, c1);

        JXStatusBar.Constraint c2 = new JXStatusBar.Constraint(JXStatusBar.Constraint.ResizeBehavior.FILL);
        c2.setFixedWidth(200);

        JXStatusBar.Constraint c4 = new JXStatusBar.Constraint(130);

        component.add(filesLoadedLabel, c2);
        component.add(filesFilteredLabel, c2);
        component.add(tagBrowserFilterLabel, c2);
        component.add(activeFiltersLabel, c2);
        component.add(mbDelayLabel, c4);
        component.add(memoryLabel, c4);

enter image description here

However as the screenshot above shows this doesnt work properly, probably because Im using the wrong LayoutManager but I cant work out what LayoutManager JXStatusBar is using I cannot see one defined in the code.

So my question is either:

  • What Layout Manager do I need to set JPanel to to align same way?
  • What is the most similar LayoutManager I can use instead to have the same effect?

Edit

Okay so I have got it basically working by hacking internal LayoutManager class from BasicStatusBarUI but I think I would prefer to just use a standard LayoutManager, is that possible ?

enter image description here

camickr
  • 321,443
  • 19
  • 166
  • 288
Paul Taylor
  • 13,411
  • 42
  • 184
  • 351
  • _but I cant work out what LayoutManager JXStatusBar is using_ Is the source code available for `JXStatusBar`? – Abra Mar 04 '22 at 10:48
  • Yes and I have looked at it - https://github.com/arotenberg/swingx but no referecne to layout manager – Paul Taylor Mar 04 '22 at 10:50
  • @Abra actually found it in BasicStatusBarUI.java but not easy to reuse, so I think my questions what is an alternative LayoutManager to use to achieve the same thing – Paul Taylor Mar 04 '22 at 10:54
  • 1
    Not sure what functionality of the JXStatusBar that you are attempting to replicate. If you like the Internal layout manager then you should be able to separate that code from the rest of the class and just set it as the layout manager for a JPanel. I would suggest a GridBagLayout provides the ability to add components with a fixed width or you can allow components to grow/shrink as required. And you can control the rate of change with each component. Or, maybe you will find the [Relative Layout](https://tips4java.wordpress.com/2008/11/02/relative-layout/) helpful. – camickr Mar 04 '22 at 15:01

1 Answers1

1

Add flatlaf-swingx.jar to your project, then JXStatusBar works fine with FlatLaf:

enter image description here

See FlatLaf addon for SwingX and issue #492

DevCharly
  • 166
  • 2