Changing Font for JLabels

Hello, I have created a small test program using a JComboBox. The purpose of this program is to change a JLabel to a certain font, based on the font that the user chooses from the JComboBox. My main concern is actually changing to font and I have no clue how to do this.
The following is the code for this test program:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class FontTest implements ActionListener{
     JFrame frame;
     JPanel contentPane;
     JComboBox font;
     JLabel fontPrompt, word;
     public FontTest(){
          frame = new JFrame("Font Styles");
          frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          contentPane = new JPanel();
          contentPane.setLayout(new BoxLayout(contentPane, BoxLayout.PAGE_AXIS));
          contentPane.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
          fontPrompt = new JLabel("Select a font: ");
          fontPrompt.setAlignmentX(JLabel.LEFT_ALIGNMENT);
          contentPane.add(fontPrompt);
          String[] names = {"Times New Roman", "Ariel"}; //any font names that are available
          font = new JComboBox(names);
          font.setAlignmentX(JComboBox.LEFT_ALIGNMENT);
          font.setSelectedIndex(0);
          font.addActionListener(this);
          contentPane.add(font);
          word = new JLabel("font styles");
          word.setBorder(BorderFactory.createEmptyBorder(20, 0, 0, 0));
          contentPane.add(word);
          frame.setContentPane(contentPane);
          frame.pack();
          frame.setVisible(true);
     public void actionPerformed(ActionEvent event){
          JComboBox comboBox = (JComboBox)event.getSource();
          String fontWord = (String)comboBox.getSelectedItem();
          if(fontWord == "Times New Roman"){//if any of these choices in the JComboBox are clicked,
                                                  //I would like the JLabel "font styles" to change font.                              
          else if(fontWord == "Ariel"){
     private static void runGUI(){
          JFrame.setDefaultLookAndFeelDecorated(true);
          FontTest display = new FontTest();
     public static void main(String[] args){
          javax.swing.SwingUtilities.invokeLater(new Runnable(){
               public void run(){
                    runGUI();
}It would be great if you guys could help me. Any font style is alright.
Thanks in advance.

Hi,
Build a Font object and call setFont on the JLabel.
Hope that help,
Jack

Similar Messages

  • Cannot change font for UTF-8 pages in FF 4.0.1

    No matter whether I change Options > Content > Default font, or go to Options > Content > Advanced and set Sans Serif for Other Languages, nothing changes—for instance, on this forum. Everything's still Times New Roman from the looks of it.
    The Sans Serif font for Other Languages is set to Arial.
    There's no Unicode entry in the list. The Other Languages is the closest I could find.
    I have Options > Content > Advanced > Allow pages to choose their own fonts… unchecked.
    I made similar changes for Western, and that worked—for pages detected as having ISO-8859-1 encoding.
    Is this a bug? Or am I doing something wrong?
    <rant>
    On a more general note, I think that the font setup in Firefox is so over-complicated. I personally want all my pages in a single font, and I don't care if some weird languages are displayed incorrectly with it. I bet that most people do want the same, even them who speak those weird languages. It's just a matter of picking one font that works for the languages you care about.
    Now that might not work perfectly for everybody so there should be an advanced option—an ability to add overrides. It should be similar to how it works now but the list of overrides should be user-customizable and '''empty by default.''' So that we regular people don't bother ourselves with encodings and languages we're never going to use.
    I wonder if I'm the only one who's disappointed with FF's font settings. Couldn't find anything on this topic on the 'net.
    </rant>

    '''Xircal:''' this does not seem to be the case. When I go to Options > Content > Advanced > Other Languages I can see that Proportional is set to Sans Serif, and that Sans-Serif is set to Arial. The following line is also in my about:config:
    font.default.x-unicode user set string sans-serif
    '''cor-el:''' yes this is the address. While on this page, if I go to View > Character Encoding, the active selection is Unicode (UTF-8).
    '''Edit:''' if I manually change this site's encoding to Western (ISO-8859-1) the font changes to that I specified for Western encoding in Advanced font options.

  • [CS2/CS3] - Changing font for TextEditBoxWidget

    Hello,
       could someone help me how to change default font for mentioned widget to f.e. Arial MS which has rich support for Unicode special symbols ?
    Thank you, marxin

    Thank you Dirk for tips where to find interfaces which manages with fonts. There is a snapshot that shows that there are 2 chars (3/8,5/8) that are not correctly drawn:
    I found an interface called "IInterfaceFonts" which has method:
    virtual voidSetFont (const PMLocaleId &locale, const int32 &interfaceElementId, const PMString &fontName, const int16 &fontSize, const int16 &fontAttributes)=0
    Could you please help me about atributes of this function if I want to use f.e. "arial" font. The font is placed in a folder WINDOWS/Fonts.
    Thank you, marxin

  • Howto set default font for JLabel & JTextField in JClient?

    Hi,
    JDev 10.1.2
    Can you please tell me how to set the default font for labels & textfields in JClient?
    For some reason the proposed font is now "Microsoft sans serif", before it was "Tahoma".
    I search the preferences all over and didn't found any clue.
    I know you can change the font of the source editor.
    I suppose the default font is taken from the OS environment, but where?
    I intend to deploy to linux so a Microsoft font doesn't suit me.
    I changed the style to bold for some labels and in this case the font parameter is part of the code.
    Any help will be appreciated.
    Frederic

    Hello
    The defaults reached thru the Terminal are not storing infos about the font used as default one in a template.
    I apologize but when I select all in a Numbers document and save it as a template, it doesn't match your requirements.
    Each time I insert a new table it defaults to HelveticaNeue.
    This is why I gave the tip which changes the font name in the Index.xml file.
    From my iDisk:
    <http://idisk.mac.com/koenigyvan-Public?view=web>
    you may download:
    :For_iWork:changeFont.zip
    which gives you the ability to do the job very easily.
    you may also download
    For_iWork:removePrintRecord.zip
    which removes the print Record embedded in our documents if this one is annoying.
    Yvan KOENIG (from FRANCE vendredi 6 juin 2008 14:57:02)

  • How could I change font for IBM 9068 A03 printer so I get better output?

    Closing as duplicate post please continue with [/questions/1014845]
    I am a linux user. In past I used Chrome for my browser. But a few months ago, my corporate changed our software and optimized it for using in Firefox. Unfortunately, the output printing font I got so bad. My printer is IBM 9068 A03 with IBM Proprinter II driver, and it's no matter about font in Chrome. Can I change font in FIrefox to get better printing output? Thankyou very very much for helping.

    see [/questions/1014845]
    Sorry linked to itself in my last post !
    Posting again to ensure you have the correct link in your emaiI.

  • Change font for entire photo book?

    Hello,
    I'm currently creating a new photo book in Aperture 3.4
    I would like to change the font for the text boxes to something else.
    Can this be done in one action/command?
    Or is it possible to change the default font (and size) that is used?
    I now have to change the font and size for every text box I want to use.
    Kind regards,
    emeu1

    I have the same question: is there a way to globally change the font in a Aperture photo book?  Bumpity-bump-bump-bump.  Thank you.

  • Changed fonts for entire system when trying to change mplayer fonts

    I was trying to make the subtitles in mplayer smaller and saw that one possible solution was to copy a new font into the mplayer/fonts folder and replace the shortcut.
    I did the following:
    #sudo cp /usr/share/fonts/TTF/times.ttf /usr/share/mplayer/subfont.ttf
    To my horror this seems to have changed the default font for the entire system. I'm able to change fonts through "obconf", but apps like conky and pypanel don't response to these changes. How can I change things back? Or at least be able to customize the font in pypanel an conky so I can get a system wide font??
    EDIT: Well, I fixed it. I just did the same, but with a font I like. Kinda weird way to change fonts, but it works.
    Last edited by Perre (2008-04-13 17:15:59)

    Still exactly the same problem after installing Arch X86

  • Change font for e72

    Hey guys is it possible to change font type in e72 or is there any theme which allows to change the font type?

    Menu/CTR panel/setting/general/personalization/standby mode/mode setting/application shortcuts/ then choose any shortcut and click on it and choose FONT MAGNIFIER it will appear on your screen then u open it to change the font size and you will be asked to restart your phone.
    I spend all the day to find it.
    Attachments:
    ghanno 003.JPG ‏485 KB

  • I need help on changing font for the subtitles in quicktime player

    Hi
    I am wondering if there is a way to change the font size for the Quicktime Player?
    I have no idea how I can do it, and this is greatly bothering me.
    If someone knows the step, may you please write the step by step process of how to change the font size?
    I will be really happy to know this
    Thnx.
    (P.s. - I also like pictures )

    They can only be changed by using an authoring app like QuickTime Player 7 Pro.

  • Change font for search results? RH 9

    I've been asked by a client if we can show the same font in the search results that we use for the Contents TOC - Trebuchet 10.  I can't find it in the skin settings.  Can anyone help?
    Thanks...

    As Column, mentioned, you must do this in the output files as far as I know.
    Go to whfform.htm <http://www.wvanweelden.eu/output_file/robohelp-9-and-earlier-webhelp/whfformhtm>  and change the lines
    setFont("Normal", "Tahoma","8pt","Black","Normal","Normal","none");
    setFont("Error", "Tahoma","8pt","Black","Normal","Normal","none");
    setFont("Hover", "Tahoma","8pt","Gray","Normal","Normal","underline");
    I believe this will change the search result fonts.
    Note: You need to save the modified whfform.htm and paste it in your output after every generation.
    Greet,
    Willam

  • Change font for control

    Is there no way for me to change the font size duiring run time (programatically)?
    I've tried doing that on the graph and slider

    How are you trying to change the font? The following code (also attached) changes the font of a CNiGraph named m_graph to bold Courier, size 15:
    void CChangeFontAtRuntimeDlg::OnSetFontButton()
    m_graph.Font.Name = "Courier";
    m_graph.Font.Bold = true;
    m_graph.Font.Size = 15;
    Attachments:
    ChangeFontAtRuntime.zip ‏14 KB

  • Changing fonts for Pop up menus

    Hi all,
    Could any tell me if there is a way to change the choose of
    fonts you can use on the pop up menu options?
    I am trying to have Arial as the first choice but my current
    option does not allow this and i cannto find a way of changing it.
    Thanks
    Mark

    harry109 wrote:
    > Hi all,
    >
    > Could any tell me if there is a way to change the choose
    of fonts you can use
    > on the pop up menu options?
    >
    > I am trying to have Arial as the first choice but my
    current option does not
    > allow this and i cannto find a way of changing it.
    Under the Appearance tab, click the font menu ad select
    Verdana, Arial,
    Helvetica, sans-serif. Highlight Verdana with your cursor and
    delete it.
    Linda Rathgeber [PVII] *Adobe Community Expert-Fireworks*
    http://www.projectseven.com
    Fireworks Newsgroup:
    news://forums.projectseven.com/fireworks/
    CSS Newsgroup: news://forums.projectseven.com/css/
    http://www.adobe.com/communities/experts/

  • Change Font for Printing

    I have message fonts set large (14pt) for screen viewing, which is too large for printing. Is there a way to specify a font to use for screen viewing and another to use for printing? I don't see any way to do this in either Mail Preferences or in the extremely-limited options available in settings when in the Print dialog.
    Given the separation-of-function philosophy evident in OS X, I would expect this to be controlled in printer settings for mail. If it is there, it's hiding.

    I've never seen font size settings in any print dialogue, this is something you need to set in the app you are using.
    Print dialogues normally let you set a % reduction for anything you are printing in a Scale menu. If you do not see that, hit the triangle button to the right of the printer name to expand the choices.

  • Change font for finder?

    hello. How do I change the font the finder uses (mainly in finder windows)? It was possible in former OSX versions, but I cannot find it in 10.4. — Sorry, this is probably trivial, but I can't find it neither in Mac Help, nor in the discussions.
    Titanium PowerBook G4 / 1,67 MHz   Mac OS X (10.4.5)  

    It's never been possible to change Finder fonts in any version of OS X without a third-party hack. There's a program called TinkerTool that will let you change Finder fonts, but it can cause problems.

  • New tab homepage and font for ff

    my problem is that with new ff 5.0 i can set up an option which will open every new tab with my home page. with the old one it worked but when i was looking for a new add on looks like the old one hasn't been upgraded to the new ff 5.0. maybe i just dont know where to look ,so then pls give me some suggestion what should i do with this, or maybe you dont have this feature for ff 5.0, so then it is my suggestion to do this because it's one of the most important features while working with new tabs to have already a webpage which you want to work with instead of taping address every time you open a new tab!!
    another thing is that somehow i changed font for the whole interface of ff and now somehow cant find where is this option where to change it again.. :( would you be so nice and help me to find this option again? font of wepage content is good. it's only about ff's interface like toolbars, the place where you type www address, bookmarks toolbar, font in name of open tabs)
    it's definitely not the option in tools -> options -> content -> font!
    I'm pretty sure that i have done this somewhere in windows. maybe somehow you will be able to help me.
    thank you very much!!
    Agnieszka

    thank you very much!! this helped me a lot with my first problem!!
    what about the second? would you be able to help me as well?

Maybe you are looking for

  • Trying to understand RSTP - Please can someone explain this?

    Hi Group I am still confused about how RSTP is implemented. From what i understand the major difference is that STP used Timers for Loop prevention whereas RSTP coordinates between neighbors via messages (proposal/aggreement) to turn on links more qu

  • Early Upgrade Fee

    I got switched to Verizon via the Alltel buyout so I'm not really sure how all this works with Verizon. I have a BlackBerry Storm and want to switch to a Droid. I have had my BlackBerry for a year and a few months. I am about 6-8 months away from NET

  • Custom Team calendar design on WebDynpro Java

    Hi, I am tryng to design a UI like Team calendar with similar functionality. Unfortunately i do not have access Utils project which is redering actual team calendar inn SAP delivered Team Calendar application. So i am not aware how they have achieved

  • Postscript generated with incorrect orientation

    I am trying to print a booklet to a postscript file from InDesign. The booklet is letter-half and 8 pages (5 spreads) with all pages on a portrait orientation. For printer I select Postscript which greys out the ability to pick paper size or orientat

  • Rebuilt thumbnails in 6.06, now library empty, cant find any photos

    Had about 20,000 photos in the library that were never well organized and after a requested thumbnail rebuild the entire thing is empty and cannot find a single photo on the drive. Have no recent backup, but scattered backups on DVD's over the years