【问题标题】:How to put the label of a AbstractButton on the bottom of the Icon?如何将 AbstractButton 的标签放在 Icon 的底部?
【发布时间】:2016-07-24 05:23:18
【问题描述】:

这是我在按钮图标底部设置标签的代码。

m_button.setIcon(large);
m_button.setLabel(m_button.getName());
m_button.setVerticalTextPosition(m_button.BOTTOM);

m_button.setMargin(BUTTON_INSETS);
m_button.setSize(BUTTON_SIZE);
m_button.setSize(20, 20);

但结果如下。

我怎样才能让它在图标的底部? 像这样:

【问题讨论】:

  • 作为第二张图片。标签正好在图标的底部。
  • 也许这会有所帮助stackoverflow.com/questions/354866/… 它使用 SwingConstants.BOTTOM 并建立水平位置。
  • @Saj setLabel 和 setText 也会这样做。尝试链接的解决方案。使用 SwingConstants 和 setHorizo​​ntalTextPosition。
  • 同时设置垂直和水平?这就是链接的解决方案。
  • @RubioRic 非常感谢。我没有设置水平文本位置。你拯救了我的一天。

标签: java swing user-interface


【解决方案1】:

设置两个水平和垂直文本位置:

JButton button = new JButton("Test", icon);
button.setHorizontalTextPosition(SwingConstants.CENTER);
button.setVerticalTextPosition(SwingConstants.BOTTOM);

【讨论】:

    猜你喜欢
    • 2020-09-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-04-14
    • 2015-04-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多