Home > Enterprise >  Replacement LayoutManager for JXStatusBar Constraints or way to use with JPanel
Replacement LayoutManager for JXStatusBar Constraints or way to use with JPanel

Time:03-08

I am using swingx library, on Windows I am now moving towards using the 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

CodePudding user response:

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

  • Related