How to get gap between JLabel's icon and text - Java Swing

Java examples for Swing:JLabel

Description

How to get gap between JLabel's icon and text

Demo Code


import javax.swing.ImageIcon;
import javax.swing.JApplet;
import javax.swing.JLabel;
 
public class Main {
       //from   w w  w. ja v  a2s .  c o  m
        public void init(){
                ImageIcon icon = new ImageIcon("images/copy.gif");
                JLabel copyLabel = new JLabel("Copy", icon, JLabel.CENTER);

                int gap = copyLabel.getIconTextGap();
                copyLabel.setIconTextGap(50);
        }
}

Related Tutorials