Wednesday, November 5, 2014

Java Jtext field pro



Change Font of JText Field

import java.awt.FlowLayout;
import java.awt.Font;
import javax.swing.JApplet;
import javax.swing.JTextField;
public class JTextFieldFontExample extends JApplet
{
 public void init()
{
this.getContentPane().setLayout(new FlowLayout());
JTextField field = new JTextField("JTextField Change Font Example",30);
Font font = new Font("Courier", Font.Bold,12);
field.setFont(font);
add(field);
   }
}

Create New JText Field

import java.awt.FlowLayout;
import javax.swing.JApplet;
import javax.swing.JTextField;
public class CreateNewJTextFieldExample extends JApplet
{
public void init()
{
this.getContentPane().setLayout(new FlowLayout());
JTextField field1 = new JTextField();
JTextField field2 = new JTextField("JTextField Default Text");
JTextField field3 = new JTextField(10);
JTextField field4 = new JTextField("JTextField Default Text", 20);
add(field1);
add(field2);
add(field3);
add(field4);               
   }
}

Create Read Only JTextField

import java.awt.FlowLayout;
import javax.swing.JApplet;
import javax.swing.JTextField;
public class CreateReadOnlyJTextFieldExample extends JApplet
{
public void init()
{
this.getContentPane().setLayout(new FlowLayout());  JTextField field = new JTextField("Read Only JTextField Example");field.setEditable(false);
add(field);
  }
}

Get Current Caret Position in JText Field

import java.awt.FlowLayout;
import javax.swing.JApplet;
import javax.swing.JTextField;
import javax.swing.event.CaretEvent;
import javax.swing.event.CaretListener;
public class GetCaretPositionInJTextFieldExample extends JApplet implements CaretListener
{
public void init()
{
this.getContentPane().setLayout(new FlowLayout());          
JTextField field = new JTextField("JTextField Caret Position Example"); add(field);
field.addCaretListener(this);
}
public void caretUpdate(CaretEvent e) { int position = e.getDot();
getAppletContext().showStatus("Caret Position :" + position);
  }
}

Create Read Only JTextField

import java.awt.FlowLayout;
import javax.swing.JApplet;
import javax.swing.JTextField;
public class CreateReadOnlyJTextFieldExample extends JApplet
{
public void init()
{
this.getContentPane().setLayout(new FlowLayout());           
JTextField field = new JTextField("Read Only JTextField Example");            
field.setEditable(false);
field.setEditable(true);    
add(field);             
   }
}

Get X and Y Coordinates of JText Field

import java.awt.FlowLayout;
import javax.swing.JApplet;
import javax.swing.JLabel;
import javax.swing.JTextField;
public class JTextFieldGetXYCoordinatesExample extends JApplet{
public void init()
{
this.getContentPane().setLayout(new FlowLayout());JTextField field = new JTextField("JTextField X Y Coordinates Example",20);
int x = field.getX();
int y = field.getY();
   }
}

JText Field Columns

import java.awt.FlowLayout;
import javax.swing.JApplet;
import javax.swing.JTextField;
public class JTextFieldColumnsExample extends JApplet
{
public void init()
{
this.getContentPane().setLayout(new FlowLayout());  JTextField field = new JTextField("JTextField Columns Example"); field.setColumns(20);
int columns = field.getColumns();
add(field);
   }
}

No comments:

Post a Comment