Setting font style -- Font Class

Hi,
How can I change the font style in the Font constructor? e.g.
Font f = new Font("Dialog", Font.PLAIN, 10);is the default font style. I want the same object but with "Arial" style. I've tried
Font f = new Font("Arial", Font.PLAIN, 10);but it doesen't work.
Any idea?
Thanks in advance

from the JavaDocs:
name - the font name. This can be a logical font name or a font face name. A logical name must be either: Dialog, DialogInput, Monospaced, Serif, or SansSerif.
You want SansSerif
Good Luck
Lee

Similar Messages

  • Setting font colors

    Is there a way to set the font color so that it isn't just white or whatever the default terminal font color is. I know there is a Font class, but I don't really understand how that works, whether I do Font.color and it will change the default changes or what. Can somebody direct me to more information that I can read up on, or if they know themselves. Thank you.

    I don't think fonts apply to terminals. They apply to GUIs, documents, and similar things that support different font types. I doubt there is a way using pure Java to change the color of text in a terminal, since that sounds like something that is OS specific.

  • Setting font and color TextItems

    This script is failing to set font, and how can I set font color?; I am new to PS Scripting:
         var originalUnit = preferences.rulerUnits
          preferences.rulerUnits = Units.INCHES
         var docRef = app.documents.add( 11, 17, 300, "Test", NewDocumentMode.CMYK)
        MyLayer = docRef.artLayers.add()
         MyLayer.kind = LayerKind.TEXT
         var myFont = app.fonts.getByName("ArialMT");
         // Set the contents of the text layer.
         var textItemRef = MyLayer.textItem
         textItemRef.font = myFont;
         textItemRef.size = UnitValue(36, 'pt');
         textItemRef.font = '_Aviano-Regular';
         textItemRef.style = "Italic";
         textItemRef.contents = "Sample Text";
         // Restore original ruler unit setting
          app.preferences.rulerUnits = originalUnit
    Thanks

    The font needs to be the postscript name, this will give you a list of them.
    var Dlog =
    "dialog{text:'Script Interface',bounds:[100,100,500,270],"+
    "FontName:DropDownList{bounds:[30,40,370,60]},"+
    "PostScriptName:DropDownList{bounds:[30,100,370,120]},"+
    "statictext0:StaticText{bounds:[40,10,200,30] , text:'Font Name'},"+
    "statictext1:StaticText{bounds:[40,70,141,87] , text:'Postscript Name'},"+
    "button0:Button{bounds:[140,130,240,150] , text:'Ok' }}";
    win = new Window(Dlog,"Use the Postscript Name in your script.");
    var item;
    var item2;
    for (var i=0,len=app.fonts.length;i<len;i++) {
      item = win.FontName.add ('item', "" + app.fonts[i].name);
      item2 = win.PostScriptName.add ('item', "" + app.fonts[i].postScriptName);   
    win.FontName.selection = win.FontName.items[0] ;
    win.PostScriptName.selection = win.PostScriptName.items[0] ;
    win.FontName.onChange = function() {
    win.PostScriptName.selection = win.PostScriptName.items[parseInt(this.selection)] ;
    $.writeln(win.PostScriptName.items[parseInt(this.selection)]);
    win.PostScriptName.onChange = function() {
    win.FontName.selection = win.FontName.items[parseInt(this.selection)] ;
    win.center();
    win.show();
    Here is your code with colour addded...
         var originalUnit = preferences.rulerUnits
          preferences.rulerUnits = Units.INCHES
          var FillColor = new SolidColor;
        FillColor.rgb.hexValue = 'ff0000';
         var docRef = app.documents.add( 11, 17, 300, "Test", NewDocumentMode.CMYK)
        MyLayer = docRef.artLayers.add()
         MyLayer.kind = LayerKind.TEXT
         var myFont = "ArialMT";
         // Set the contents of the text layer.
         var textItemRef = MyLayer.textItem
         textItemRef.font = myFont;
         textItemRef.size = UnitValue(36, 'pt');
         textItemRef.font = myFont;
         //textItemRef.style = "Italic";
         textItemRef.fauxItalic = true;
         textItemRef.contents = "Sample Text";
         textItemRef.color = FillColor;
         // Restore original ruler unit setting
          app.preferences.rulerUnits = originalUnit

  • Set Font globally in JavaFX

    How I can set the Font type globally in JavaFX application?
    Is there any solution which I can use? in JavaFX 8 the default Font is changed I would like to use the same Font used in JavaFX 2.2.
    Ref Set Font globally in JavaFX - Stack Overflow

    Add a stylesheet with the rule
    .root { -fx-font: 13 "Comic Sans MS"; }
    or whatever font size and family you want.
    You can also use an inline style on the root node, e.g.,
    Parent root = scene.getRoot();
    root.setStyle("-fx-font: 13 \"Comic Sans MS\"; ");

  • How to set font for title and message in JOptionPane?

    Hi,
    I have following test code.
    JOptionPane.showMessageDialog(null, "Some Alert Message", "Alert", JOptionPane.ERROR_MESSAGE);In this code can we set font for "Some Alert Message", "Alert"?
    Regards,
    Kalyani......

    roll-your-own?
    import javax.swing.*;
    class Testing
      public static void main(String[] args)
        JDialog.setDefaultLookAndFeelDecorated(true);
        JOptionPane optionPane = new JOptionPane("<html><font size='5'>Your message here</font></html>");
        optionPane.setOptionType(JOptionPane.DEFAULT_OPTION);
        optionPane.setMessageType(JOptionPane.ERROR_MESSAGE);
        JDialog dialog = optionPane.createDialog(null, "Alert");
        dialog.getLayeredPane().getComponent(1).setFont(dialog.getFont().deriveFont(18f));//size = 18/whatever
        dialog.setModal(true);
        dialog.setVisible(true);
    }

  • How to set font for  JOptionPane.showMessageDialog() ?

    Hi,
    I want to set font for JOptionPane.showMessageDialog(). I have tried with following but it did not worked.
    javax.swing.UIManager.put("JOptionPane.font", "Verdana"); Do any one have idea how to do this. Your suggestion would be helpfull to me.
    Thank you.

    Then you'll have to loop over the components in the JOptionPane and setFont for each JButton. My SwingUtils class (search the net using Darryl SwingUtils, I can't give you a link as it's blocked from my office) can make this easier.
    Sample code:import darrylbu.util.SwingUtils;
    import java.awt.Font;
    import javax.swing.*;
    import javax.swing.plaf.FontUIResource;
    public class OptionPaneFonts {
       public static void main(String[] args) {
          UIManager.put("OptionPane.messageFont", new FontUIResource(new Font(
                  "Verdana", Font.BOLD, 32)));
          SwingUtilities.invokeLater(new Runnable() {
             @Override
             public void run() {
                new OptionPaneFonts().makeUI();
       public void makeUI() {
          JOptionPane pane = new JOptionPane("So it's a date?",
                  JOptionPane.QUESTION_MESSAGE,
                  JOptionPane.YES_NO_CANCEL_OPTION,
                  UIManager.getIcon("OptionPane.questionIcon"),
                  new String[]{"Okey-dokey", "Not on your life!",
                     "Let me think about it"
                  }, null);
          for (JButton button : SwingUtils.getDescendantsOfType(JButton.class, pane)) {
             button.setFont(new Font("Tahoma", Font.ITALIC, 18));
          JDialog dialog = new JDialog((JWindow) null);
          dialog.setModal(true);
          dialog.add(pane);
          dialog.pack();
          dialog.setLocationRelativeTo(null);
          dialog.setVisible(true);
    }db
    Edited by: DarrylBurke -- shortened the code

  • Understanding this message panel with the set font

    heyall, can someone explain to me how this messagepanel class works with setNewFont class, I cannot understand the correlation in the below lines?? i.e. there is no getFont class in the messagepanel so why use it?what does it do?
    //Set font for the message
            Font font = messagePanel.getFont();
            messagePanel.setFont(new Font(font.getName(),fontStyle, font.getSize()));
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class CheckBoxDemo  extends ButtonDemo{
        //Create three check boxes to control the display of message
        private JCheckBox jchkCentered = new JCheckBox("Centered");
        private JCheckBox jchkBold = new JCheckBox("Bold");
        private JCheckBox jchkItalic = new JCheckBox("Italic");
        public static void main(String[]args){
            CheckBoxDemo frame = new CheckBoxDemo();
            frame.setTitle("CheckBoxDemo");
            frame.setLocationRelativeTo(null);
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.setSize(500,200);
            frame.setVisible(true);
        public CheckBoxDemo() {
            //Set mnemonic keys
            jchkCentered.setMnemonic('C');
            jchkBold.setMnemonic('B');
            jchkItalic.setMnemonic('I');
            //Create a new panel to hold check boxes
            JPanel jpCheckBoxes = new JPanel();
            jpCheckBoxes.setLayout(new GridLayout(3,1));
            jpCheckBoxes.add(jchkCentered);
            jpCheckBoxes.add(jchkBold);
            jpCheckBoxes.add(jchkItalic);
            add(jpCheckBoxes,BorderLayout.EAST);
            //Registar listeners with checkboxes
            jchkCentered.addActionListener(new ActionListener(){
                public void actionPerformed(ActionEvent e){
                    messagePanel.setCentered(jchkCentered.isSelected());
                    jchkCentered.addActionListener(new ActionListener(){
                public void actionPerformed(ActionEvent e){
                    setNewFont();
                    jchkCentered.addActionListener(new ActionListener(){
                public void actionPerformed(ActionEvent e){
                    setNewFont();
        private void setNewFont() {
            int fontStyle = Font.PLAIN;
            fontStyle += (jchkBold.isSelected() ? Font.BOLD : Font.PLAIN);
            fontStyle += (jchkItalic.isSelected() ? Font.BOLD : Font.PLAIN);
            //Set font for the message
            Font font = messagePanel.getFont();
            messagePanel.setFont(new Font(font.getName(),fontStyle, font.getSize()));
    import java.awt.FontMetrics;
      import java.awt.Dimension;
      import java.awt.Graphics;
      import javax.swing.JPanel;
      public class MessagePanel extends JPanel{
        /** The message to be displayed */
        private String message = "Welcome to Java";
        /** The x coordinate where the message is displayed */
        private int xCoordinate = 20;
        /** The y coordinate where the message is displayed */
        private int yCoordinate = 20;
        /** Indicate whether the message is displayed in the center */
        private boolean centered;
        /** The interval for moving the message horizontally and vertically */
        private int interval = 10;
        /** Construct with default properties */
      //  public MessagePanel() {
        /** Construct a message panel with a specified message */
        public MessagePanel(String message) {
          this.message = message;
        /** Return message */
        public String getMessage() {
          return message;
        /** Set a new message */
        public void setMessage(String message) {
          this.message = message;
          repaint();
        /** Return xCoordinator */
        public int getXCoordinate() {
          return xCoordinate;
        /** Set a new xCoordinator */
        public void setXCoordinate(int x) {
          this.xCoordinate = x;
          repaint();
        /** Return yCoordinator */
        public int getYCoordinate() {
          return yCoordinate;
        /** Set a new yCoordinator */
        public void setYCoordinate(int y) {
          this.yCoordinate = y;
          repaint();
       /** Return centered */
        public boolean isCentered() {
          return centered;
        /** Set a new centered */
        public void setCentered(boolean centered) {
          this.centered = centered;
          repaint();
        /** Return interval */
        public int getInterval() {
          return interval;
        /** Set a new interval */
        public void setInterval(int interval) {
          this.interval = interval;
          repaint();
        /** Paint the message */
        protected void paintComponent(Graphics g) {
          super.paintComponent(g);
          if (centered) {
            // Get font metrics for the current font
            FontMetrics fm = g.getFontMetrics();
            // Find the center location to display
            int stringWidth = fm.stringWidth(message);
            int stringAscent = fm.getAscent();
            // Get the position of the leftmost character in the baseline
            xCoordinate = getWidth() / 2 - stringWidth / 2;
            yCoordinate = getHeight() / 2 + stringAscent / 2;
          g.drawString(message, xCoordinate, yCoordinate);
        /** Move the message left */
        public void moveLeft() {
          xCoordinate -= interval;
          repaint();
        /** Move the message right */
        public void moveRight() {
          xCoordinate += interval;
          repaint();
        /** Move the message up */
        public void moveUp() {
          yCoordinate -= interval;
          repaint();
        /** Move the message down */
        public void moveDown() {
         yCoordinate += interval;
          repaint();
        /** Override get method for preferredSize */
        public Dimension getPreferredSize() {
          return new Dimension(200, 30);
      }

    ah right so because there is an import fontmetrics api attached to that is a getFont method......i see now

  • Printing Problem with already set Font

    Post Author: tejas_kishanwala
    CA Forum: General
    hi,
    i have created a report using Crystal Report 9 with font Draft 10CPI using Printer EPSON FX-2175 on Windows XP with SP2.  after then when i call this report from my .NET Application (developed on VS 2005). the report is not showing as well printing with the already set Font (Draft 10CPI) Kindly do needful for the same. Tejas Kishanwala 

    Post Author: mewdied
    CA Forum: General
    Is the font Draft 10CPI a printer font?  If it is, you are running across a limitation of .NET not Crystal Reports.  .NET only supports True type and Open type fonts.  Microsoft has a KB about it, but I cannot find it right now.

  • Setting Font Color and Bold Property in ALV Grid

    I have a requirement to set the font in particular ALV Cells  in red color.
    Also this font (text) has to be set to Bold.
    I know how to set cell coloring in ALV Grid, but have no idea regarding how to set font color.
    Could please give me an idea/code segment/suggestion.
    Thank You!

    Please refer this post
    Coloring of ROWS in ALV tree

  • Can't set FONT in iCHAT

    When I try to hit SET FONT in iChat prefs, nothing happens.
    Fonts work in other apps.
    ?????

    I found it. DUH... the font window opened behind my prefs window.

  • [Solved] css setting font family, ff3 vs ie7

    In my css, I've set 'font-family: sans;' in body { }, and in ff3 on my Arch laptop, it displays correctlly. In ie7 on my wifes vista laptop, it still reverts back to w/e serif font it uses if it can't find one set by the web page. I have no idea why this is happening, and I can't seem to fix it. Can anyone give me a hand?
    Last edited by Sjoden (2009-01-04 03:07:09)

    Agh, well, I looked at thayer's blog to see if that worked in both browsers and it did, so I checked to see how he had his fonts set up.
    font-family: Arial, DejaVu Sans, sans-serif;
    The closest I got to that was 'font-family: Arial, DejaVu, sans;'

  • Anyone know Flash CS3 embed font's Glyphs Range!! with font class(no TextField )

    I have add some font by Font class in the library
    (TextFeild.embedFonts=true)
    but the font's glyphs looks not enough.
    when i use text String " ü ä ö ß π
    à â ç è é ê ë î ï
    ô ù û œ "
    only the "π" and "œ" is can be visible.
    Font.hasGlyphs also return false;
    if i only create a TextField, and Click the Embed button
    selection glyphs range.
    the text will be fine.
    but i won't use TextField by drag to the stage
    i heard in flex:
    @font-face {
    src:local("Arial");
    fontFamily: myFont;
    flashType: true;
    unicodeRange:
    U+0041-U+005A, /* [A..Z] */
    U+0061-U+007A, /* a-z */
    U+0030-U+0039, /* [0..9] */
    U+002E-U+002E; /* [.] */
    so what can i do in Flash CS 3?
    thanks a lot
    i really tried working on this.maybe i just need go back use
    the .....TextField.

    Im not sure if u can do it with flash cs3.
    i change a little ur code to :
    package {
    //import flash.util.describeType;
    import flash.display.MovieClip;
    import flash.text.TextField;
    import flash.text.TextFormat;
    import flash.text.AntiAliasType;
    import flash.text.TextFieldAutoSize;
    import flash.text.TextFormatAlign;
    import flash.text.Font;
       public class Test extends MovieClip {
          // be sure this is pointing to a ttf font in your hardrive
          [Embed(source="arial.ttf", fontFamily="foo", mimeType="application/x-font-truetype")]
          public var arialfont:Class;
          public function Test() {
              Font.registerFont(arialfont)
                var format:TextFormat          = new TextFormat();
              format.font              = "foo";
              format.color                = 0xFFFFFF;
              format.size                 = 130;
              var label:TextField         = new TextField();
              label.embedFonts            = true;
              label.autoSize              = TextFieldAutoSize.LEFT;
              label.antiAliasType         = AntiAliasType.ADVANCED;
              label.defaultTextFormat     = format;
              label.text                  = "Hello World!";
              addChild(label);
              trace(label.text);
              label.setTextFormat(format);
    and it works fine with flash cs4, only first time it will ask to confirm flex sdk location ( have to have flex sdk to use embed, u can downlaod it free from adobe.com)
    hope that helps

  • How do I set font default in aperture?

    how do I set font default in aperture?

    how do I set font default in aperture?
    Do you want to change the size of the fonts or the shape for the fonts in the user interface or in the products (books, webpages)?
    Aperture does not allow to change the fonts used in the graphical user interface, neither the size nor the shape. To change the fonts for the products (books, etc.), pick a theme with the fonts you like.
    Regards
    Léonie

  • Set font size for ChoiceGroup

    Hi,
    Is there any way to set font size of the String elements of ChoiceGroup

    Hi,
    Yes, there is, but only if you're using MIDP2.0.
    Check the API documentation of ChoiceGroup and see that there's a setFont(.., ..) method. The given index (int value) identifies the index of the element in the list for which the font will be set. This means that different elements in one choicegroup can have different fonts.
    Test it carefully, I've noticed that not all devices show correct behaviour on this. Also note that certain devices ignore certain font settings (for example italics, because a lot of native implementations won't have a font in italics).
    Good luck!

  • How to use Underline feature in Font Class

    I am making an applet to test the Bold, Italic and Underline feature of any Font but there is no such Font Constant to Underline the Text. Can you help me to get Underlined Text through Font class or any such alternative to achieve my goal?
    Thanks.
    Arjun Thadani
    email: [email protected]

    A type of underline is the character '\u0332',
    Try for example.
    char[] chs = new char[]{(char)0x30,(char)0x0332,(char)0x41,(char)0x0332};
    str = new String(chs);

  • Set font on a text

    Hi!
    I've got some problem with setting font on a text, this is my coed:
    var ar_delaney_e:Font = new ar_delaney();
    textcount=1;
    //Setting a variable to     ar_delaney_e
    this["font_"+String(textcount)] = "ar_delaney_e";
    //Create a textFormat
    var textFormat:TextFormat = new TextFormat();
    //Setting font textformat fon to ar_delaney_e??
    textFormat.font = this["font_"+String(textcount)];
    //Set textformat to my text
    myText.defaultTextFormat = textFormat;
    Fon is embedded hav also tried textFormat.font = this["font_"+String(textcount)].fontName; instead of textFormat.font = this["font_"+String(textcount)]; but no one of this will work, how can you fix this?

    On stage I got a button with instance name add_text_btn, and a mc called "knapp_bild". So when pressing add_text_btn the function func_add_text_btn creates a movie clip with a text in it and also variables for size, color and font for the text. the two variables size and color works fine.
    add_text_btn.addEventListener(MouseEvent.CLICK, func_add_text_btn);
    function func_add_text_btn(event:MouseEvent):void{
    textcount++;
    var MovieClip:MovieClip = new MovieClip();
    MovieClip.x = 80;
    MovieClip.y = 60;
    MovieClip.alpha = 1;
    MovieClip.name="mc_text"+String(textcount);
    //Variables for font, size and color
    this["size_"+String(textcount)] = 40;
    this["color_"+String(textcount)] = "0x00CC00";
    this["font_"+String(textcount)] = "ar_delaney_e";
    textFormat.font = this["font_"+String(textcount)].fontName;
    textFormat.size = this["size_"+String(textcount)];
    textFormat.color = this["color_"+String(textcount)];
    var textField:TextField = new TextField()
    textField.defaultTextFormat = textFormat;
    textField.autoSize="left";
    textField.text = 'Text '+String(textcount);
    textField.name = "text"+String(textcount);  // give them names
    textField.background=false;
    textField.embedFonts=true;
    var mc_name=String("mc_text"+String(textcount));
    knapp_bild.addChild(MovieClip);
    MovieClip.addChild(textField);
    textField.mouseEnabled=false;
    MovieClip.width=textField.width;
    Later on in the program this["font_"+String(textcount)] will change but it dosen't work in the func_add_text_btn function now so let's just try to fix that first. Hope you can see something that mabe won't work and just ask if you got any qusetion. Thanks for your help!

Maybe you are looking for