Showing posts with label jlist. Show all posts
Showing posts with label jlist. Show all posts

Set JList text color

Source code below will show you, how to set JList text color base on RGB. You can get RGB value for your color using "Color picker" at above.

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


import javax.swing.JList;
import javax.swing.JFrame;

import java.awt.Color;
import java.awt.FlowLayout;

public class SetJListTextColor
{
public static void main(String[]args)
{
//Create JList contents
String[]listContents={"Cow","Sheep","Horse"};

//Create list using JList
JList list=new JList(listContents);

//Create JFrame with title ( Set JList text color )
JFrame frame=new JFrame("Set JList text color");

//Set JFrame layout to FlowLayout
frame.setLayout(new FlowLayout());

//Set color base on RGB
//You can get RGB value for your color at "Color picker" at above
//R=255
//G=0
//B=0
Color color=new Color(255,0,0);

//Set JList text color to color that you choose
list.setForeground(color);

//Add JList into JFrame
frame.add(list);

//Set default close operation for JFrame
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

//Set JFrame size
frame.setSize(500,300);

//Make JFrame visible
frame.setVisible(true);
}
}


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

Set JList background color

Source code below will show you, how to set JList background color base on RGB. You can get RGB value for your color using "Color picker" at above.

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


import javax.swing.JList;
import javax.swing.JFrame;

import java.awt.Color;
import java.awt.FlowLayout;

public class SetJListBackgroundColor
{
public static void main(String[]args)
{
//Create JList contents
String[]listContents={"Cow","Sheep","Horse"};

//Create list using JList
JList list=new JList(listContents);

//Create JFrame with title ( Set JList background color )
JFrame frame=new JFrame("Set JList background color");

//Set JFrame layout to FlowLayout
frame.setLayout(new FlowLayout());

//Set color base on RGB
//You can get RGB value for your color at "Color picker" at above
//R=255
//G=0
//B=0
Color color=new Color(255,0,0);

//Set JList background color to color that you choose
list.setBackground(color);

//Add JList into JFrame
frame.add(list);

//Set default close operation for JFrame
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

//Set JFrame size
frame.setSize(500,300);

//Make JFrame visible
frame.setVisible(true);
}
}


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

Create list using JList

Source code below will show you, how to create list in java using JList.

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


import javax.swing.JList;
import javax.swing.JFrame;

import java.awt.FlowLayout;

public class CreateListUsingJList
{
public static void main(String[]args)
{
//Create contents for JList using array
//Using String as array type
String[]listContents={"HI","HA","HU"};

//Create a list using JList
JList list=new JList(listContents);

//Create a JFrame that will be use to put JList into it
JFrame frame=new JFrame("Create list using JList");

//set JFrame layout to FlowLayout
frame.setLayout(new FlowLayout());

//add created JList into JFrame
frame.add(list);

//set default close operation for JFrame
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

//set JFrame size
frame.setSize(400,400);

//make JFrame visible. So we can see it
frame.setVisible(true);
}
}


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

Add JList into JFrame

Source code below will show you, how to create a list in java using JList. After that we will add it, into a jframe.

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


import javax.swing.JList;
import javax.swing.JFrame;

import java.awt.FlowLayout;

public class AddJListIntoJFrame
{
public static void main(String[]args)
{
//Create contents for JList
String[]listContents={"Honda","Toyota","Ford","Ferrari","Cooper"};

//Create a JList with it contents
JList myList=new JList(listContents);

//Create a JFrame with title ( Add JList into JFrame )
JFrame frame=new JFrame("Add JList into JFrame");

//Set layout for JFrame
frame.setLayout(new FlowLayout());

//Add JList into JFrame
frame.add(myList);

//Set default close operation for JFrame
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

//Set JFrame size
frame.setSize(400,400);

//Make JFrame visible. So we can see it.
frame.setVisible(true);
}
}


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

RELAXING NATURE VIDEO