Only the first band is displayed correctly in Flamingo's swing ribbon

313 Views Asked by At

I am trying to implement a basic example of Flamingo, a Windows-like ribbon emulator for Java apps, but I am stuck. The first band is correctly displayed, but in the second one the text "Edition" is displayed - not its components - and when I click on it it is displayed again under the first "Edition" band, and again, etc. It seems it has a reference on itself, although the code is the same as for the first band.

Here is my code:

package tries;

import org.pushingpixels.flamingo.api.common.CommandButtonDisplayState;
import org.pushingpixels.flamingo.api.common.JCommandButton;
import org.pushingpixels.flamingo.api.common.icon.ImageWrapperResizableIcon;
import org.pushingpixels.flamingo.api.common.icon.ResizableIcon;
import org.pushingpixels.flamingo.api.ribbon.JRibbonBand;
import org.pushingpixels.flamingo.api.ribbon.JRibbonFrame;
import org.pushingpixels.flamingo.api.ribbon.RibbonTask;
import org.pushingpixels.flamingo.api.ribbon.resize.CoreRibbonResizePolicies;
import org.pushingpixels.flamingo.api.ribbon.resize.IconRibbonBandResizePolicy;
import org.pushingpixels.substance.api.SubstanceLookAndFeel;
import org.pushingpixels.substance.api.skin.CeruleanSkin;

import javax.swing.*;
import java.awt.*;
import java.util.Arrays;

import static org.pushingpixels.flamingo.api.ribbon.RibbonElementPriority.MEDIUM;
import static org.pushingpixels.flamingo.api.ribbon.RibbonElementPriority.TOP;

public class RibbonTry extends JRibbonFrame {

  public static void main(String[] args) {

    JFrame.setDefaultLookAndFeelDecorated(true);
    SwingUtilities.invokeLater(() -> {
      SubstanceLookAndFeel.setSkin(new CeruleanSkin());
      RibbonTry ribbonTry = new RibbonTry();

      JRibbonBand bnd_store = new JRibbonBand("Stockage", null);
      bnd_store.setResizePolicies(Arrays.asList
              (new IconRibbonBandResizePolicy(bnd_store.getControlPanel())));
      JRibbonBand bnd_edition = new JRibbonBand("Edition", null);
      bnd_edition.setResizePolicies(Arrays.asList(
              new IconRibbonBandResizePolicy(bnd_edition.getControlPanel())));
      JRibbonBand bnd_searches = new JRibbonBand("Recherches", null);
      bnd_searches.setResizePolicies(Arrays.asList(
              new IconRibbonBandResizePolicy(bnd_searches.getControlPanel())));


      JCommandButton btn_saveInFile = new JCommandButton("Enregistrer",
              getResizableIconFromResource("save1.png"));
      btn_saveInFile.setDisplayState(CommandButtonDisplayState.BIG);
      btn_saveInFile
              .setCommandButtonKind(JCommandButton.CommandButtonKind.ACTION_ONLY);
      bnd_store.addCommandButton(btn_saveInFile, TOP);
      btn_saveInFile.setDisplayState(CommandButtonDisplayState.BIG);
      JCommandButton btn_loadFromFile = new JCommandButton("Charger",
              getResizableIconFromResource("load1.png"));
      btn_loadFromFile
              .setCommandButtonKind(JCommandButton.CommandButtonKind.ACTION_ONLY);
      bnd_store.addCommandButton(btn_loadFromFile, TOP);
      bnd_store.setResizePolicies(Arrays.asList(
              new CoreRibbonResizePolicies.None(bnd_store.getControlPanel()),
              new IconRibbonBandResizePolicy(bnd_store.getControlPanel())
      ));
      JCommandButton btn_saveInTable = new JCommandButton("Stocker dans table",
              getResizableIconFromResource("add-row.png"));
      btn_saveInTable.setDisplayState(CommandButtonDisplayState.MEDIUM);
      btn_saveInTable
              .setCommandButtonKind(JCommandButton.CommandButtonKind.ACTION_ONLY);
      bnd_edition.addCommandButton(btn_saveInTable, MEDIUM);

      JCommandButton btn_cancelFromTable = new JCommandButton("Annuler les " +
              "changements",
              getResizableIconFromResource("open-in-browser.png"));
      btn_cancelFromTable.setDisplayState(CommandButtonDisplayState.MEDIUM);
      btn_cancelFromTable
              .setCommandButtonKind(JCommandButton.CommandButtonKind.ACTION_ONLY);
      bnd_edition.addCommandButton(btn_cancelFromTable, MEDIUM);

      JCommandButton btn_deleteInTable = new JCommandButton("Effacer dans table",
              getResizableIconFromResource("delete-row.png"));
      btn_deleteInTable.setDisplayState(CommandButtonDisplayState.MEDIUM);
      btn_deleteInTable
              .setCommandButtonKind(JCommandButton.CommandButtonKind.ACTION_ONLY);
      bnd_edition.addCommandButton(btn_deleteInTable, MEDIUM);

      RibbonTask task1 = new RibbonTask("Commandes", bnd_store, bnd_edition,
              bnd_searches);
      ribbonTry.getRibbon().addTask(task1);


      ribbonTry.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
      ribbonTry.setLocation(300, 200);
      ribbonTry.pack();
      ribbonTry.setMinimumSize(new Dimension(500, 300));
      ribbonTry.setVisible(true);

    });

  }

  private static ResizableIcon getResizableIconFromResource(String resource) {
    return ImageWrapperResizableIcon
            .getIcon(RibbonTry.class.getClassLoader().getResource(resource), new
                    Dimension(48, 48));
  }


}
1

There are 1 best solutions below

0
On BEST ANSWER

You're calling setResizePolicies on all three bands and pass only IconRibbonBandResizePolicy - which is the one that forces the ribbon band into iconified state.

Then you reconfigure bnd_store with two resize policies - none and iconified, which makes its content visible. But the other two remain iconified.

There's a bug there in Flamingo that allows calling setResizePolicies with only iconified policy. This is tracked by https://github.com/kirill-grouchnikov/flamingo/issues/17