Solved

Changing font color in Java

Posted on 2011-02-14
4
735 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Configure a Bean in an XML file 4 42
maven module vs maven project 3 46
Chrome and Firefox Java 5 50
Cisco ASA: Java web start no go, asdm launcher no go 3 34
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…

808 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