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



Home Answers Viewqa Java-Beginners Add color to background but I can't labels or textfields

Have Programming Question? Ask it here!
 
 
 


Jose Argueta
Add color to background but I can't labels or textfields
8 Answer(s)      2 years and 7 months ago
Posted in : Java Beginners


Please help me to fix this.

public static void main(String[] args) { JFrame f = new JFrame(); SchoolOption f1 = new SchoolOption(); Color c = new Color(128,0,0); Container con = f.getContentPane(); con.setBackground(c); f.setDefaultCloseOperation(JFrame.EXITONCLOSE); f.setSize(400, 120); f.setTitle("Bloomfield College Student Registration System "); f.setResizable(false); f.setLocationRelativeTo(null); f.setVisible(true); } }


Advertisement
View Answers

December 18, 2011 at 6:20 AM


print("public static void main(String[] args)
{
    JFrame f = new JFrame();
    SchoolOption f1 = new SchoolOption();
    Color c = new Color(128,0,0);
    Container con = f.getContentPane();
    con.setBackground(c);
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.setSize(400, 120);
    f.setTitle("Bloomfield College Student Registration System ");
    f.setResizable(false);
    f.setLocationRelativeTo(null);
    f.setVisible(true);
}

}");



December 18, 2011 at 11:07 AM


For label you need to create and initialize the JLabel class object and add it to container. Inorder to do that you need to import javax.swing.* So the code must contain the following lines to add label and text field JLabel l1=new JLabel("Enter name"); JTextField tf1=new JTextField(10); con.add(l1); con.add(tf1);



December 18, 2011 at 12:45 PM


I am very new to Java, I followed your instruction and this is what I came up with, am I missing something?

print("{
    JFrame f = new JFrame();
    JLabel l1 = new JLabel();
    JTextField tf1 = new JTextField ();

    SchoolOption f1 = new SchoolOption();

    Color c = new Color(128,0,0);
    Container con = f.getContentPane();

    con.setBackground(c);
    con.add(l1);
    con.add(tf1);
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.setSize(400, 120);
    f.setTitle("Bloomfield College Student Registration System");
    f.setResizable(false);
    f.setLocationRelativeTo(null);
    f.setVisible(true);
    l1.setVisible(true);
    //tf1.setVisible(true)

}");


December 18, 2011 at 12:52 PM


It has white background now instead of Maroon



December 19, 2011 at 4:36 PM


import java.awt.*;
import javax.swing.*;

class Test{
    public static void main(String[] args){
    JFrame f = new JFrame();
    JLabel l1 = new JLabel("Name: ");
    JTextField tf1 = new JTextField ();
    f.setLayout(null);
    l1.setBounds(10,10,100,20);
    tf1.setBounds(120,10,120,20);
    SchoolOption f1 = new SchoolOption();
    f.add(l1);
    f.add(tf1);
    Color c = new Color(128,0,0);
    Container con = f.getContentPane();

    con.setBackground(c);

    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.setSize(400, 120);
    f.setTitle("Bloomfield College Student Registration System");
    f.setResizable(false);
    f.setLocationRelativeTo(null);
    f.setVisible(true);
    l1.setVisible(true);
   }
}


December 19, 2011 at 4:36 PM


import java.awt.*;
import javax.swing.*;

class Test{
    public static void main(String[] args){
    JFrame f = new JFrame();
    JLabel l1 = new JLabel("Name: ");
    JTextField tf1 = new JTextField ();
    f.setLayout(null);
    l1.setBounds(10,10,100,20);
    tf1.setBounds(120,10,120,20);
    SchoolOption f1 = new SchoolOption();
    f.add(l1);
    f.add(tf1);
    Color c = new Color(128,0,0);
    Container con = f.getContentPane();

    con.setBackground(c);

    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.setSize(400, 120);
    f.setTitle("Bloomfield College Student Registration System");
    f.setResizable(false);
    f.setLocationRelativeTo(null);
    f.setVisible(true);
    l1.setVisible(true);
   }
}


December 19, 2011 at 4:38 PM


import java.awt.*;
import javax.swing.*;

class Test{
    public static void main(String[] args){
    JFrame f = new JFrame();
    JLabel l1 = new JLabel("Name: ");
    JTextField tf1 = new JTextField ();
    f.setLayout(null);
    l1.setBounds(10,10,100,20);
    tf1.setBounds(120,10,120,20);
    SchoolOption f1 = new SchoolOption();
    f.add(l1);
    f.add(tf1);
    Color c = new Color(128,0,0);
    Container con = f.getContentPane();

    con.setBackground(c);

    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.setSize(400, 120);
    f.setTitle("Bloomfield College Student Registration System");
    f.setResizable(false);
    f.setLocationRelativeTo(null);
    f.setVisible(true);
    l1.setVisible(true);
   }
}


December 19, 2011 at 4:38 PM


import java.awt.*;
import javax.swing.*;

class Test{
    public static void main(String[] args){
    JFrame f = new JFrame();
    JLabel l1 = new JLabel("Name: ");
    JTextField tf1 = new JTextField ();
    f.setLayout(null);
    l1.setBounds(10,10,100,20);
    tf1.setBounds(120,10,120,20);
    SchoolOption f1 = new SchoolOption();
    f.add(l1);
    f.add(tf1);
    Color c = new Color(128,0,0);
    Container con = f.getContentPane();

    con.setBackground(c);

    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.setSize(400, 120);
    f.setTitle("Bloomfield College Student Registration System");
    f.setResizable(false);
    f.setLocationRelativeTo(null);
    f.setVisible(true);
    l1.setVisible(true);
   }
}


Related Tutorials/Questions & Answers:
Add color to background but I can't labels or textfields
Add color to background but I can't labels or textfields  Please help... = new JFrame(); SchoolOption f1 = new SchoolOption(); Color c = new Color(128,0,0); Container con = f.getContentPane
Background color blocks all labels and textfields
Background color blocks all labels and textfields  I added background color but I dont see textfields and labels anymore, please help. What am I missing? (" JFrame f = new JFrame(); SchoolOption f1 = new SchoolOption(); Color c
Advertisements
labels,textfields,buttons
labels,textfields,buttons  how to set the labels,textfields,buttons at certain positions such that we can add them without layout managers? my program is to design a login page with image and these labels at exact positions
UITextfield Background Color
is ..it's showing a background color. Though my text field color is white. Can you please suggest.. , how can i remove the background color of text field. Thanks!  ...UITextfield Background Color  In my iPhone application, i am using
jframe background color not showing
jframe background color not showing  jframe background color is not showing. please suggest.   Just add the background color to JPanel and then add it to JFrame. For example .. JFrame myFrame = new JFrame(); JPanel
div background color in html
div background color in html   How to change the background color of DIV in HTML
uiscrollview background color
uiscrollview background color  Is it possible to set the uiscrollview background color in iPhone application
HTML document's background color
HTML document's background color  How to set a HTML document's background color
changing uiview background color
changing uiview background color  changing UIView background color in ios   self.view.backgroundColor = [UIColor colorWithRed:244.0f/255.0f green:230.0f/255.0f blue:183.0f/255.0f alpha:1.0f
HTML - table background color.
HTML - table background color. Description : Here, you will see how to specifies the table back ground color in html page. The <table > is a html... the background color of table.  Code : <!DOCTYPE html PUBLIC "
Javascript background color - Java Beginners
Javascript background color  Hi How to compare background color...; Hi Friend, If you want to change the background color of the textbox, try the following code: Change background Color function check
Changing background color using JavaScript
Changing background color using JavaScript  Hi Sir Is there any way to change the background color using JavaScript ? Please mention code with your... below function to change the background color & call it wherever it needed
UIWebView Background Color
UIWebView Background Color If you wanted to change the background color on UIWebView in iPhone SDK, then you required to set the background color of UIWebView...). Where as setBackgroundColor will allow you to change the color of background area
changing Background Color
changing Background Color   ... change background color of a pdf file. You can change the background color... color) to set the background color of that chunk. Here we pass
pdf background color
pdf background color      ... the background of the pdf file as well as the size of a pdf file irrespective of the fact... the background of the pdf file which you have built. To make a program over
UITableView Background Color
UITableView Background Color To change the background color of UITableView...]; The above line will change the default background color into gray color. You can... Selected Background Color UIImageView *selectedBackground = [[UIImageView
Change background color of text box - Java Beginners
Change background color of text box  Hi how can i change the background color to red of Javascript text box when ever user enters an incorrect value while on entering a correct value its background color should change green
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
how to color the Eclipse editor background programmatically?
how to color the Eclipse editor background programmatically?  I have to color specific portion(background) of the of the Eclipse editor by running... as start line number and end line number and do the color in background portion
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... the background color after every 5 seconds. Here is the code
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
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
i need to answer this Question but i can't do it probably
i need to answer this Question but i can't do it probably   use the web to locate the lyrics to the traditional song"The Twelve Days of Christmas" the song contains a list of gifts received for the holiday.the list is cumulative
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
how to create menubar and the below background color/image in java swing
how to create menubar and the below background color/image in java swing  how to create menubar and the below background color/image in java swing
Change Background color using Custom Tag
Change Background color using Custom Tag In this program, We will create a Custom Tag which changes the background color. JSP Custom Tags : Provide... : In this Example, We will create a Custom Tag which changes the background color
How to add image in panel as background in net beans IDE?
How to add image in panel as background in net beans IDE?  How to add image in panel as background in net beans IDE
background
background  how to add image as background to a frame
I am from .net background, I want to learn SOA.
I am from .net background, I want to learn SOA.  Hi I am from .net background, I want to learn SOA. Could it possible for me to learn SOA, I suppose SOA includes Java. I dont have knowledge of java. Please help Thanks  
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
textfields and update - SQL
textfields and update  how can i retrieve a table from a database and put in on the textfields using jdbc?and at the same time update the items on the database
How I can Set Transparent Background Image to Panel - Java Beginners
How I can Set Transparent Background Image to Panel  Sir ,How I can Set Transperent Background Image to Jpanel. plz Help Me
How to set pdf background color.
How to set pdf background color. In this example, you will see how to set back ground color of pdf in struts2.  index.jsp <html> <...;/title></head> <body> <p>Background of file
Dynamically adding textbox and labels
Dynamically adding textbox and labels  Sir, In my application I want to insert texbox and labels dynamically and want to insert database field value in that generated label. Plz help me, Thanks in advance
dynamic textfields
dynamic textfields  Hi, I am a fresher and joined recently in one... Bran has 80%, Cheerios has 40%. If we add them up, you just ate 170% of the RDA... that i want to have a button as "addingtrdients" .if i click on to the button
how can i add hibernate plugin to eclipse?
how can i add hibernate plugin to eclipse?  how can i add hibernate plugin to eclipse
Background Image for Navigation Bar
Background Image for Navigation Bar The tutorial illustrates how to add background image for UINavigationBar. To add a background image to UINavigationBar... given code and add it into your implementation file. @implementation
why this can't
why this can't  import java.util.*; class Dash{ public static void main(String args[]){ int x0=100; int[] x1=new int[3]; int[][] x2=new int[3][3]; int[][][] x3=new int[3][3][3
Labels in Struts 2.0 - Struts
Labels in Struts 2.0   Hello, how to get the Label name from properties file
I need add my java program with a picture.
I need add my java program with a picture.  Good evng Frnds Friends i created 1 jar file in my desktop. I need add this program with 1 picture... of opening Picture. I think most of the softwares are like that . They are first
textfields and update - SQL
textfields and update  how can i put retrieved table from a database to the textfields using jdbc?and at the same time update the items on the database..   Hello Friend As per ur 1st Q: Read the data from
Filling Color in Excel Using JSP
and background color .Then at last we add the style sheet into cellls and finally we add... a sheet  and then  fill background color ,pattern and forground color... is used to fill the background color. You can be used the following fields
UITableView Background Image
UITableView Background Image  How to set an image as a background of UITableView in iPhone SDK   I think, we can't
making of dynamic textfields using swings
making of dynamic textfields using swings  How to make dynamic textfields using java swings
Jbutton[] background & foregroundcolor change
foreground and background color is changed. the remaining jbutton foreground and background color are not changed. next i select button[9] then the button[5] foreground... the color of the selected JButton in java swing. I am create JButton in an array
How to design a background, design a background, a background
color: First set the foreground and background color. Clouds: Go to Filter menu... How to design a background       If you don't have background, don't worry because you will learn here
Set Background Colors and Images in HTML
to set a background color in HTML. In this Tutorial, the code describe you an example that helps you to set background color in HTML. The code begin...;bgcolor> in HTML depicts you the color background of web page.    
div style background
div style background  How to add background color to a div? What is the code of div style background?   Hi, You can use the following code: <div style="background-color: #ccffcc;"> <p>Content</p> <
Advertisements
 

 

 

DMCA.com