Changing font color in Java

Posted on 2011-02-14
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( );
        addRunnerInfoPanelsAndLabel( );

        this.getContentPane().add( primaryPanel );
//        this.setBackground(;
    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"),
                                              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));

Open in new window

Question by:Darkejo1
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
LVL 92

Expert Comment

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

Accepted Solution

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));

Author Comment

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

JLabel.setFont(new Font("Courier New", Font.ITALIC, 12));

Author Closing Comment

ID: 34892782
Worked great!

Featured Post

Technology Partners: 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

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Suggested Courses

732 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