gpt4 book ai didi

java - JButton 中的图标位置

转载 作者:搜寻专家 更新时间:2023-11-01 01:42:04 26 4
gpt4 key购买 nike

是否可以更改 JButton 中的图标图像位置?

现在是这样的:

enter image description here

我想把图标移到更左边。

我已尝试更改文本对齐方式,但它无法正常工作:

myButton.setHorizontalTextPosition(SwingConstants.RIGHT);

最佳答案

看看 JButton.setHorizontalAlignment(int align)

Sets the horizontal alignment of the icon and text. AbstractButton's default is SwingConstants.CENTER, but subclasses such as JCheckBox may use a different default.

你可以设置:

  • SwingConstants.RIGHT
  • SwingConstants.LEFT
  • SwingConstants.CENTER
  • SwingConstants.LEADING
  • SwingConstants.TRAILING

关于java - JButton 中的图标位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31640205/

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