This example creates a JLabel component with an icon.

    // Fetch icon
    Icon icon = new ImageIcon("icon.gif");
    
    // Create a label with text and an icon; the icon appears to the left of the text
    JLabel label = new JLabel("Text Label", icon, JLabel.CENTER);
    
    // Create a label with only an icon
    label = new JLabel(icon);

This example adds or replaces the icon in an existing JLabel component:

    // Add an icon to an existing label
    label.setIcon(icon);

The methods to control the position of the icon and text within a JLabel component are identical to those of a JButton. See also e747 在按钮上移动图标的位置, e748 在按钮上移动图标和标注的位置, e749 设置按钮上图标和标注的间隔, and e750 在按钮上加上不可用图标

相关文章:

  • 2021-06-19
  • 2022-12-23
  • 2022-12-23
  • 2021-11-28
  • 2022-12-23
  • 2021-05-31
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-12-08
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-07-16
  • 2021-04-28
相关资源
相似解决方案