1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
/* Get or Set Gap Between JLabel's Icon and Text Example This java example shows how to get gap between JLabel's icon and text using Java Swing JLabel class. */ import javax.swing.ImageIcon; import javax.swing.JApplet; import javax.swing.JLabel; /* <applet code="JLabelGapBetweenTextAndIconExample" width=200 height=200> </applet> */ public class JLabelGapBetweenTextAndIconExample extends JApplet{ public void init(){ //create ImageIcon ImageIcon icon = new ImageIcon("images/copy.gif"); //create JLabel JLabel copyLabel = new JLabel("Copy", icon, JLabel.CENTER); add(copyLabel); /* * To determine gap between Icon and Text use, * int getIconTextGap() * method. * * Return value is the number of pixels between * icon and text. * * Default gap between JLabel's text and Icon is * 4 pixels. */ int gap = copyLabel.getIconTextGap(); /* * To set gap between JLabel's icon and text, use * void setIconTextGap(int gap) * method. * * where gap is number of pixels. */ copyLabel.setIconTextGap(50); } } |
Add Comment