Set JTextField selection color

Complete source code below will show you how to set JTextField selection color.

***************************************************************
COMPLETE SOURCE CODE FOR : SetJTextFieldSelectionColor.java
***************************************************************


import javax.swing.*;

import java.awt.*;

public class SetJTextFieldSelectionColor
{
public static void main(String[]args)
{
JTextField jtf=new JTextField("Select this text");

//Color that will use as JTextField's selection color
//It is base on RGB value
//Red=255
//Green=0
//Blue=0
//You can use color picker at above to get RGB value
Color selectionColor=new Color(255,0,0);

//Set JTextField selection color
jtf.setSelectionColor(selectionColor);

JFrame myWindow=new JFrame("Set JTextField selection color");

myWindow.add(jtf);
myWindow.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
myWindow.setSize(400,50);
myWindow.setLocationRelativeTo(null);
myWindow.setVisible(true);
}
}


***************************************************************
JUST COMPILE AND EXECUTE IT
***************************************************************

Set JTextField caret color

Complete source code below will show you, how to set JTextField caret color.

****************************************************************
COMPLETE SOURCE CODE FOR : SetJTextFieldCaretColor.java
****************************************************************


import javax.swing.*;

import java.awt.*;

public class SetJTextFieldCaretColor
{
public static void main(String[]args)
{
JTextField jtf=new JTextField(20);
jtf.setFont(new Font("Verdana",Font.BOLD,34));

JFrame myFrame=new JFrame("Set JTextField caret color");

//Set caret color base on RGB value
//R=255
//G=0
//B=0
//You can get RGB value from color picker at above
jtf.setCaretColor(new Color(255,0,0));

myFrame.setLayout(new FlowLayout());
myFrame.add(jtf);
myFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
myFrame.pack();
myFrame.setLocationRelativeTo(null);
myFrame.setVisible(true);
}
}


****************************************************************
JUST COMPILE AND EXECUTE IT
****************************************************************

JTextField caret


RELAXING NATURE VIDEO