java - JButton 中的图标位置

标签 java swing jbutton imageicon

是否可以更改 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/

相关文章:

java - 更改所有选项卡 Pane 面板 java swing 的颜色的按钮操作

java - 自定义 JButton : setText doesn't have effect

java - Java 中的类库是什么?

java - 使用速度模板打印 JasperReports

java - 不断收到预期的错误类、接口(interface)或枚举

java - JTable 使用双表排序以在 Java 1.4 中保持同步

Javax Swing JTable::getModel 与 JTable::getColumnModel

java - 使用 JButton ActionListener 在同一个包中运行不同的类

Java:从嵌套在HashMap中的列表中获取条目列表

java.lang.ArrayStoreException IBM Websphere