Thursday, October 30, 2014

Java Applet Pro



Set Icon for JLabel  

import javax.swing.ImageIcon;
import javax.swing.JApplet;
import javax.swing.JLabel;  
public class SetJLabelIconExample extends JApplet
{     
public void init()
{
JLabel label1 = new JLabel("JLabel Set Icon Example.");
add(label1);
label1.setIcon(new ImageIcon("images/copy.gif"));
   }
}

Set JLabel Border

import java.awt.Color;
import javax.swing.BorderFactory;
import javax.swing.JApplet;
import javax.swing.JLabel;
import javax.swing.border.Border;
public class JLabelSetBorderExample extends JApplet
{
public void init()
{
JLabel label1 = new JLabel("JLabel Create Border Example."); add(label1); Border border = BorderFactory.createLineBorder(Color.blue);
label1.setBorder(border);
   }
}

Set Vertical Alignment of JLabel

import javax.swing.JApplet;
import javax.swing.JLabel;
public class JLabelVerticalAlignmentExample extends JApplet
{
public void init()
{
JLabel label1 = new JLabel("JLabel Get Horizontal Alignment Example.");add(label1);
int alignment = label1.getVerticalAlignment();
switch(alignment)
{
 case JLabel.Left:
label1.setText("Left");
break;
case JLabel.Center:
label1.setText("Center");
break;
case JLabel.Right:
label1.setText("Right");
break;
case JLabel.Leading:
label1.setText("Leading");
break;
case JLabel.Trailing:
label1.setText("Trailing");
break;                     
}
label1.setVerticalAlignment(JLabel.Center);
   }
}

Show or Hide JLabel

import java.awt.Color;
import javax.swing.JApplet;
import javax.swing.JLabel;
public class JLabelShowHideExample extends JApplet
{    
public void init()
{
JLabel label1 = new JLabel("JLabel Show Or Hide Example.");
add(label1);
label1.setVisible(false);
  }
}

No comments:

Post a Comment