【问题标题】:How to vertically align text and image above a JRadioButton?如何在 JRadioButton 上方垂直对齐文本和图像?
【发布时间】:2012-01-29 23:34:16
【问题描述】:

是否可以同时对齐JRadioButton图标上方的文字和图像?

编辑 -
好吧,显然在构造函数中设置图标实际上替换了默认的JRadioButton 图标,这是我没想到的。看起来我可能不得不使用两个单独的组件并将它们放入同一个容器中。

【问题讨论】:

  • UI 委托使用图标。带有自定义图标的ButtonGroupJToggleButton 是否可以替代?

标签: java swing alignment jradiobutton


【解决方案1】:
JRadioButton radioB = new JRasioButton (...);

radioB.setVerticalTextPosition(JLabel.BOTTOM);

【讨论】:

    【解决方案2】:

    这将设置 JRadioButton 上方的文本:

    radiobutton.setHorizontalTextPosition(SwingConstants.CENTER);
    radiobutton.setVerticalTextPosition(JRadioButton.TOP);
    

    是的,使用 setIcon 方法替换了 JRadioButton 图标。

    【讨论】:

      猜你喜欢
      • 2021-08-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-04-06
      • 2015-04-30
      • 2020-10-07
      • 1970-01-01
      • 2011-09-25
      相关资源
      最近更新 更多