1. 程式人生 > >e740. 向標簽中加入一個圖標

e740. 向標簽中加入一個圖標

posit appear 可用 ron new osi this appears component

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 在按鈕上加上不可用圖標.

e740. 向標簽中加入一個圖標