火烈鸟的摇摆带:只有第一个乐队才能正确显示

时间:2017-12-14 16:35:17

标签: java swing radiance-flamingo

我正在尝试实现一个基本的火烈鸟示例,一个类似于Windows的带状仿真器,但是我被卡住了:第一个乐队正确显示,但在第二个乐队正式显示#34;版本&#34 ;显示 - 而不是它的组件 - 当我点击它时,它会再次显示在第一个"版本"乐队,再一次......等似乎它有自己的参考,虽然代码与第一乐队相同。

这是我的代码:

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 个答案:

答案 0 :(得分:1)

您在所有三个波段上调用setResizePolicies并仅传递IconRibbonBandResizePolicy - 这是强制功能区变为图标化状态的一个。

然后使用两个调整大小策略重新配置bnd_store - none和iconified,这使其内容可见。但其他两个仍然是图标化的。

Flamingo中存在一个错误,允许只使用图标化策略调用setResizePolicies。这由https://github.com/kirill-grouchnikov/flamingo/issues/17

跟踪