Solved

Changing font color in Java

Posted on 2011-02-14
4
737 Views
Last Modified: 2013-11-24
I'm trying to change the font of the output, but for some reason it's not working. In question are lines 68-71. I'm trying to change the font to Gray. Any help would be appreciated.
import javax.swing.*;
import java.awt.*;
import java.text.*;


  
public class FrameOfPanels extends JFrame
{

    // Instance variables
    private JPanel primaryPanel;
    
    /**
     * Constructor for objects of class FrameOfPanels
     */
    public FrameOfPanels(String title )
    {
        super( title );        
        setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE ); 
        
        primaryPanel = new JPanel( );
        primaryPanel.setBackground( Color.green );
        
        addRunnerInfoPanelsAndLabel( );

        this.getContentPane().add( primaryPanel );
        
//        this.setBackground(Color.black);
        this.pack();
        this.setSize(700,300);
        this.setVisible(true);
    }
    
    private void addRunnerInfoPanelsAndLabel( )
    {
        RunnerInfoPanel panelForRunner1;
        RunnerInfoPanel panelForRunner2;
        RunnerInfoPanel panelForRunner3;
        
        int r = 99;
        int g = 150;
        int b = 135;
        Color custom = new Color(r, g, b);
     
       

        panelForRunner1 = new RunnerInfoPanel( new ImageIcon("image3.jpg"),
                                               "Darke",
                                               "Jordon",
                                               "GVSU",
                                               5,
                                               900,
                                               1120,
                                              custom) ;
        panelForRunner2 = new RunnerInfoPanel( new ImageIcon("image2.jpg"),
                                               Color.gray );
        panelForRunner3 = new RunnerInfoPanel( new ImageIcon("image1.jpg"),Color.white );
      
        primaryPanel.add( panelForRunner1 );
        primaryPanel.add( panelForRunner2 );
        primaryPanel.add( panelForRunner3 );
        
        double averageTime = (double)(panelForRunner1.getRunner( ).getSeconds( ) +
                                      panelForRunner2.getRunner( ).getSeconds( ) +
                                      panelForRunner3.getRunner( ).getSeconds( ) ) / 3;
        
        DecimalFormat dfmt = new DecimalFormat( "###,###.##" );        
        primaryPanel.add( new JLabel( "Average time in seconds of all runners: " +
                                          dfmt.format( averageTime ))); 
       primaryPanel.setFont(new Font("Courier New", Font.ITALIC, 12));
       primaryPanel.setForeground(Color.GRAY);

Open in new window

0
Comment
Question by:Darkejo1
  • 2
  • 2
4 Comments
 
LVL 92

Expert Comment

by:objects
ID: 34892703
you need to change the color of the label, not the panel
0
 
LVL 92

Accepted Solution

by:
objects earned 500 total points
ID: 34892709
JLabel label = new JLabel( "Average time in seconds of all runners: " +
                                          dfmt.format( averageTime ));
label.setFont(new Font("Courier New", Font.ITALIC, 12));
label.setForeground(Color.GRAY);
primaryPanel.add(label);
0
 

Author Comment

by:Darkejo1
ID: 34892767
I'm assuming I did something wrong?

JLabel.setFont(new Font("Courier New", Font.ITALIC, 12));
JLabel.setForeground(Color.GRAY);
0
 

Author Closing Comment

by:Darkejo1
ID: 34892782
Worked great!
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
how to install java on RHEL image on EC2 4 52
null output 3 42
Java: anonymous class 4 37
junit as external jar or library 7 37
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

685 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question