Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Java-Beginners How to change backgroundcolor and foreground color of JLabel in Java
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


shweta
How to change backgroundcolor and foreground color of JLabel in Java
1 Answer(s)      4 years and 6 months ago
Posted in : Java Beginners


How to change backgroundcolor and foreground color of JLabel in Java

Advertisement
View Answers

April 2, 2010 at 11:24 AM


Hi Friend,

Try the following code:

import java.io.*;
import java.awt.*;
import javax.swing.*;
import java.awt.image.*;
import javax.imageio.*;

class DisplayData{
JLabel lab;
JTextField text;
JButton button;
JPanel p;
JFrame f;

DisplayData(){
lab=new JLabel("Name");

text= new JTextField(20);
button= new JButton("Submit");
p=new JPanel(new GridLayout(2,2));
f=new JFrame();
lab.setOpaque(true);

lab.setForeground(Color.red);
lab.setBackground(Color.yellow);
p.add(lab);
p.add(text);
p.add(button);
f.add(p);
f.pack();
f.setVisible(true);
}
public static void main(String[] args) {
DisplayData data=new DisplayData();
}
}

Thanks


Related Tutorials/Questions & Answers:
How to change backgroundcolor and foreground color of JLabel in Java - Java Beginners
How to change backgroundcolor and foreground color of JLabel in Java  How to change backgroundcolor and foreground color of JLabel in Java  ...*; class DisplayData{ JLabel lab; JTextField text; JButton button; JPanel p
how to change color of titlebar in java
how to change color of titlebar in java  pls help
Advertisements
select the foreground color for a label
select the foreground color for a label  (Using JScrollBar) Write a program that uses scroll bars to select the foreground color for a label, Three... of the color. Use a title border on the panel that holds the scroll bars
How to create Runtime time jLabel in java swing ?
How to create Runtime time jLabel in java swing ?   hi sir. my problem is that i want to display database row on a jLabel. Suppose i retrived a table from database & i want to display its row value on jLabel. i m facing
color change
color change  how to change the color in circle using scrollbar
How can I change UIButton title color?
How can I change UIButton title color?  Hi, I have a button in my iPhone/iPad application. I want to change the color of the text when user clicks..., You have to set the color of the button for a particular state say
How to change the color of a base64-encoded png image JQuery?
How to change the color of a base64-encoded png image JQuery?  I am going to change the colors of the pixels of a png image(which is in base64 format.... the original image is shown, but the color does not change. Do you know why
how to change div background color in javascript
how to change div background color in javascript  how to change div background color in javascript ?   <div id="Name">   <div class="content">      <h2>Your Name here</h2>       <p>First
Change background color of text box - Java Beginners
Change background color of text box  Hi how can i change... while on entering a correct value its background color should change green... problem. Please try the code. Change background Color function
Java Servlet Change Background Color
Java Servlet Change Background Color You can provide an effective way to the web page by changing the background color of the web page. In servlet, you can do this by using javascript. Here, we are going to change the background color
how to change background color in dojo tab container - Framework
how to change background color in dojo tab container  how to change background color in dojo tab container
Change the color of the selected tab
Change the color of the selected tab Swing provides different methods to give color effects which gives a presentable look to the components. In this section, you will learn how to change the color of the selected tab. For this, we have
how do you change the message box to a specific color
how do you change the message box to a specific color  How do you change the message box color to a specific color? I can get the color to change with each input but i cant give it a specific color. Example I'm trying to change
How to change table row color when click on Hyper Link in jsp?
How to change table row color when click on Hyper Link in jsp?  I use... row2 row3.. when click on the link1 automatically change the the row1 color,similarly when click on the link2 automatically change the the row2
JLabel
JLabel  how to give dimensions to JLabel
JLabel class - Java Beginners
JLabel class  what are the superclasses of the JLabel class? Thanks taylordk@nationwide.com  Hi Friend, JComponent class... of JLabel class. Thanks
Changing JLabel with a jcombobox - Java Beginners
Changing JLabel with a jcombobox  Hi, I have a JLabel which should change when i select an item from JCombobox.I have some calculations after i get a value from the combo,the result of which i have to display using a JLabel I
change player dress color
change player dress color  Hai friends, Can we change player dress color using J2ME. Please provide me an code for this. I can able to attain three colors only. Send the code to mail id. vijaikiranit@gmail.com
How to set the Gradient Color as a background color for Java Frame?
How to set the Gradient Color as a background color for Java Frame?  How to set the Gradient Color as a background color for Java Frame
JavaScript change background color automatically
JavaScript change background color automatically In this section, you will learn how to change the background color of the web page automatically. Now..., we have used using the Math.random(). The window.setTimeout() function change
change color according to the database value
change color according to the database value  any one know how to get values from database ( 1 or 0 ) and according to that change the color ( red or green) of given list
To change the color of text hyperlinks midway
To change the color of text hyperlinks midway   Is there a way to change the color of text hyperlinks midway through a page? If so, what code do I use
To change the color of text hyperlinks midway
To change the color of text hyperlinks midway   Is there a way to change the color of text hyperlinks midway through a page? If so, what code do I use
To change the color of text hyperlinks midway
To change the color of text hyperlinks midway   Is there a way to change the color of text hyperlinks midway through a page? If so, what code do I use
Change Color and Font of text
Change Color and Font of text       This section illustrates you how to change color... to render text and the TextAttribute.FOREGROUND sets the color. The values
MKMapView Change Red Pin Color
MKMapView Change Red Pin Color  MKMapView Change Pin Color Hi... of custom pin. But however on click it changes to red color pin. Can any one please tell me how can i show the same image ever after it's taped.   
change color of back ground using switch
change color of back ground using switch   how to change back ground color according to day using switch case
Jbutton[] background & foregroundcolor change
Jbutton[] background & foregroundcolor change  how to change the color of the selected JButton in java swing. I am create JButton in an array... foreground and background color is changed. the remaining jbutton foreground
changing Chunk Color
change the color of chunk color .This example tell you how you can change the color of chunk and how you can add fonts and gives the size of the fonts... changing Chunk Color     
color changing - Java Beginners
color changing  sir how to change the color of the selected tab in java swing  Hi Friend, Try the following code: import javax.swing...., BorderLayout.CENTER); tab.add("Tab 1", new JLabel("This is Tabbed Pane 1")); tab.add
how to add date and change date in java - netbeans
how to add date and change date in java - netbeans  I need to code use to increase date How to get date after 30 days using netbeans
 

 

 

DMCA.com