gpt4 book ai didi

java - Flamingo 的 swing 功能区中仅正确显示第一 strip

转载 作者:行者123 更新时间:2023-12-02 11:52:09 26 4
gpt4 key购买 nike

我正在尝试实现 Flamingo 的基本示例,这是一个用于 Java 应用程序的类似于 Windows 的功能区模拟器,但我陷入了困境。第一个带正确显示,但在第二个带中显示文本“版本” - 而不是其组件 - 当我单击它时,它会再次显示在第一个“版本”带下,然后再次显示,依此类推。看来尽管代码与第一个频段相同,但它本身有一个引用。

这是我的代码:

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));
}


}

最佳答案

您正在对所有三个带区调用 setResizePolicies,并仅传递 IconRibbonBandResizePolicy - 这是强制功能区带区进入图标化状态的策略。

然后,您使用两个调整大小策略重新配置 bnd_store - 无和图标化,这使其内容可见。但另外两个仍然被图标化。

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

关于java - Flamingo 的 swing 功能区中仅正确显示第一 strip ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47818155/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com