JText Field Disable Enable
import
java.awt.FlowLayout;
import
javax.swing.JApplet;
import
javax.swing.JTextField;
public class
JTextFieldDisableExample extends JApplet
{
public void init()
{
this.getContentPane().setLayout(new
FlowLayout());JTextField field = new JTextField("JTextField Disable Enable
Example",20); field.setEnabled(false);
add(field);
}
}
JText Field Horizontal
Alignment
import
java.awt.FlowLayout;
import
javax.swing.JApplet;
import
javax.swing.JTextField;
public class
JTextFieldHorizontalAlignmentExample extends JApplet
{
public void init()
{
this.getContentPane().setLayout(new
FlowLayout());JTextField field = new JTextField("JTextField Horizontal
Alignment Example", 10);
nt horizontalAlignment
= field.getHorizontalAlignment();
switch(horizontalAlignment)
{
case JTextField.Left:
field.setText("Left");
break;
case JTextField.Right:
field.setText("Right");
break;
case JTextField.Center:
field.setText("Center");
break;
case JTextField.Leading:
field.setText("Leading");
break;
case JTextField.Trailing:
field.setText("Trailing");
break;
}
add(field);
}
}
JText Field Show Hide
import
java.awt.FlowLayout;
import
javax.swing.JApplet;
import
javax.swing.JTextField;
public class
JTextFieldShowHideExample extends JApplet
{
public void init()
{
this.getContentPane().setLayout(new
FlowLayout());JTextField field = new JTextField("JTextField Show Hide
Example", 10);
field.setVisible(false);
add(field);
}
}
JText Field ToolTip
import
java.awt.FlowLayout;
import
javax.swing.JApplet;
import
javax.swing.JTextField
public class JTextFieldTooltipExample
extends JApplet
{
public void init()
{
this.getContentPane().setLayout(new
FlowLayout());
JTextField field = new
JTextField("JTextField ToolTip Example",20);
field.setToolTipText("This
is JTextField's ToolTip");
String toolTip =
field.getToolTipText();
add(field);
}
}
Set Background Color of JText
Field
import java.awt.Color;
import
java.awt.FlowLayout;
import
javax.swing.JApplet;
import
javax.swing.JTextField;
public class
JTextFieldBackgroundColorExample extends JApplet
{
public void init()
{
this.getContentPane().setLayout(new
FlowLayout()); JTextField field = new JTextField("JTextField Background
Color Example",20);Color color = Color.GRAY;
field.setBackground(color);
add(field);
}
}
Set Foreground Color of JText
Field
import java.awt.Color;
import
java.awt.FlowLayout;
import
javax.swing.JApplet;
import
javax.swing.JTextField;
public class
JTextFieldForegroundColorExample extends JApplet
{
public void init()
{
this.getContentPane().setLayout(new
FlowLayout()); JTextField field = new JTextField("JTextField Foreground
Color Example",20); Color color = Color.RED;
field.setForeground(color);
add(field);
}
}
Set JText Field Border
import java.awt.Color;
import
java.awt.FlowLayout;
import
javax.swing.BorderFactory;
import
javax.swing.JApplet;
import
javax.swing.JLabel;
import
javax.swing.JTextField;
import
javax.swing.border.Border;
public class
JTextFieldSetBorderExample extends JApplet
{
public void init()
{
this.getContentPane().setLayout(new
FlowLayout());
JTextField field = new
JTextField("JTextField Border Example",20);
Border border =
BorderFactory.createLineBorder(Color.red);
field.setBorder(border);
add(field);
}
}
No comments:
Post a Comment