Showing posts with label jcombobox. Show all posts
Showing posts with label jcombobox. Show all posts

Set JComboBox text color

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

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


import javax.swing.JComboBox;
import javax.swing.JFrame;

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

public class SetJComboBoxTextColor
{
public static void main(String[]args)
{
//Create JComboBox contents
String[]comboBoxContents={"Cow","Sheep","Horse"};

//Create comboBox using JComboBox
JComboBox comboBox=new JComboBox(comboBoxContents);

//Create JFrame with title ( Set JComboBox text color )
JFrame frame=new JFrame("Set JComboBox 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 JComboBox text color to color that you choose
comboBox.setForeground(color);

//Add JComboBox into JFrame
frame.add(comboBox);

//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 JComboBox background color

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

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


import javax.swing.JComboBox;
import javax.swing.JFrame;

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

public class SetJComboBoxBackgroundColor
{
public static void main(String[]args)
{
//Create JComboBox contents
String[]comboBoxContents={"Cow","Sheep","Horse"};

//Create comboBox using JComboBox
JComboBox comboBox=new JComboBox(comboBoxContents);

//Create JFrame with title ( Set JComboBox background color )
JFrame frame=new JFrame("Set JComboBox 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 JComboBox background color to color that you choose
comboBox.setBackground(color);

//Add JComboBox into JFrame
frame.add(comboBox);

//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 combo box using JComboBox

Source code below will show you, how to create a combo box in java using JComboBox class.

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


import javax.swing.JComboBox;
import javax.swing.JFrame;

import java.awt.FlowLayout;

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

//Create a combo box using JComboBox
JComboBox comboBox=new JComboBox(comboBoxContents);

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

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

//add created JComboBox into JFrame
frame.add(comboBox);

//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 JComboBox into JFrame

Source code below will show you how create contents for JComboBox. After that we will add JComboBox into a JFrame.

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


import javax.swing.JComboBox;
import javax.swing.JFrame;

import java.awt.FlowLayout;

public class AddJComboBoxIntoJFrame
{
public static void main(String[]args)
{
//Create combo box contents from type String
String[]comboBoxContents={"Chicken","Duck","Cow","Sheep"};

//Create combo box using JComboBox
JComboBox myComboBox=new JComboBox(comboBoxContents);

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

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

//Add JComboBox into JFrame
frame.add(myComboBox);

//Set 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