Solved

Changing font color in Java

Posted on 2011-02-14
4
730 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
Comment Utility
you need to change the color of the label, not the panel
0
 
LVL 92

Accepted Solution

by:
objects earned 500 total points
Comment Utility
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
Comment Utility
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
Comment Utility
Worked great!
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Suggested Solutions

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
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 …

744 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now