Showing posts with label selection. Show all posts
Showing posts with label selection. Show all posts

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
***************************************************************

RELAXING NATURE VIDEO