Welcome to the Java Programming Forums

The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Combine fonts on JLabel

  1. #1
    Junior Member
    Join Date
    Mar 2010
    Thanked 0 Times in 0 Posts

    Default Combine fonts on JLabel

    I am trying to combine fonts on a JLabel and do not seem to have any success

    JLabel title = new JLabel("Title:");
    //title.setFont(new Font ("Arial",Font.BOLD,10));
    JLabel titleLabel = new JLabel(title.getText() + myRecording.getTitle());
    //titleLabel.setFont(new Font("Book Antiqua",Font.PLAIN,12));
    JLabel fLabel = new JLabel(title.getText() + titleLabel.getText());

    I would like "Title:" and the text returned from getTitle() to have two differend fonts. Is this possible?

  2. #2
    Forum VIP
    Join Date
    Jul 2010
    Thanked 329 Times in 305 Posts

    Default Re: Combine fonts on JLabel

    I'm lazy, so I'll give you the tutorial quote (http://docs.oracle.com/javase/tutori...s/label.html):
    By specifying HTML code in a label's text, you can give the label various characteristics such as multiple lines, multiple fonts or multiple colors. If the label uses just a single color or font, you can avoid the overhead of HTML processing by using the setForeground or setFont method instead. See Using HTML in Swing Components for details.
    Here is the link to Using HTML in Swing Components.

    When asking for help, please follow these guidelines to receive better and more prompt help:
    1. Put your code in Java Tags. To do this, put [highlight=java] before your code and [/highlight] after your code.
    2. Give full details of errors and provide us with as much information about the situation as possible.
    3. Give us an example of what the output should look like when done correctly.

    Join the Airline Management Simulation Game to manage your own airline against other users in a virtual recreation of the United States Airline Industry. For more details, visit: http://airlinegame.orgfree.com/

Similar Threads

  1. Loop through JLabel and change JLabel
    By JoeBrown in forum What's Wrong With My Code?
    Replies: 2
    Last Post: April 11th, 2012, 12:52 PM
  2. Java fonts
    By Ludicrous in forum Java Theory & Questions
    Replies: 2
    Last Post: March 31st, 2012, 05:39 PM
  3. [SOLVED] I'm trying to combine 2 files into 1. Please help
    By mickey2012 in forum File I/O & Other I/O Streams
    Replies: 3
    Last Post: March 7th, 2012, 08:31 PM
  4. How do I combine two strings in an array?
    By SkyAphid in forum Collections and Generics
    Replies: 3
    Last Post: September 15th, 2011, 06:20 PM
  5. Click to start and drawString fonts
    By Campos in forum Java Applets
    Replies: 3
    Last Post: July 24th, 2009, 02:24 PM